Package lejos.nxt.comm

Examples of lejos.nxt.comm.BTConnection


  /**
   * Sets node in waiting for connection mode.
   */
  public BTConnection connect() {
    BTConnection btc = null;
    System.out.println("Wait for connection...");
    while (true) {
      btc = Bluetooth.waitForConnection();
      if (btc == null) {
        System.out.println("No connection!");
        continue;
      }
      System.out.println("Connected.");
      btc.setIOMode(NXTConnection.RAW);
      break;
    }
    return btc;
  }
View Full Code Here


  /**
   * Connects to node as master
   */
  public BTConnection connect(){
    BTConnection btc = null;

    RemoteDevice btrd = remoteNode.getRemoteDevice();

    int iCount = 0;
    while (true) {
      if(iCount==10) {
        iCount = 3;
      }
      else {
        iCount++;
      }
      if (btrd == null) {
        System.out.println("No such device!");
        continue;
      }

      btc = Bluetooth.connect(btrd);


      if (btc == null) {
        System.out.println("Connect "+remoteNode.getName()+" failed");
        try{
          Thread.sleep(iCount*1000);
        }catch(Exception e) {
          System.out.println("sleep problems");
        }
        continue;
      }
      else{
        System.out.println("Connected to "+remoteNode.getName()+".");
        btc.setIOMode(NXTConnection.RAW);
        break;
      }
    }
   
    return btc;
View Full Code Here

 
  /**
   * Sets node in waiting for connection mode.
   */
  public BTConnection connect() {
    BTConnection btc = null;
    System.out.println("Wait for connection...");
    while (true) {
      btc = Bluetooth.waitForConnection();
      if (btc == null) {
        System.out.println("No connection!");
        continue;
      }
      System.out.println("Connected.");
      btc.setIOMode(NXTConnection.RAW);
      break;
    }
    return btc;
  }
View Full Code Here

   * Connects to node as master
   *
   * @param Node
   */
  public BTConnection connect(){
    BTConnection btc = null;

    RemoteDevice btrd = remoteNode.getRemoteDevice();
    int iCount = 0;
    while (true) {
      if(iCount==10) {
        iCount = 3;
      }
      else {
        iCount++;
      }
      if (btrd == null) {
        System.out.println("No such device!");
        continue;
      }
     
      btc = Bluetooth.connect(btrd);
     
     
      if (btc == null) {
        System.out.println("Connect "+remoteNode.getName()+" failed");
        try{
          Thread.sleep(iCount*1000);
        }catch(Exception e) {
          System.out.println("sleep problems");
        }
        continue;
       
      }
      else{
      System.out.println("Connected to "+remoteNode.getName()+".");
      btc.setIOMode(NXTConnection.RAW);
      break;
      }
    }
    return btc;
  }
View Full Code Here

 
  private static void draw() throws IOException {
    // Wait for connection
    LCD.drawString("Menunggu koneksi", 0, 0);
    LCD.refresh();
    BTConnection btc = Bluetooth.waitForConnection();
   
    DataInputStream dis = btc.openDataInputStream();
   
    LCD.clearDisplay();
    LCD.drawString("Sudah dapat koneksi", 0, 0);
    LCD.refresh();
   
View Full Code Here

  private static void connect() {
    try {
      LCD.drawString("Menunggu koneksi", 0, 0);
      LCD.refresh();
      BTConnection btc = Bluetooth.waitForConnection();

      DataInputStream dis = btc.openDataInputStream();

      LCD.drawString("Sudah dapat koneksi", 0, 1);
      LCD.refresh();

      char read = dis.readChar();
      String arah = "";

      LCD.drawString("Pesan : " + read, 0, 2);
      LCD.refresh();

      while (read != 'e') {
        // Ambil semua petunjuk arah dari Hayate sampai karakter
        // sentinel
        arah += read;
        read = dis.readChar();
      }

      dis.close();
      btc.close();
      LCD.drawString("Arah " + arah, 0, 0);
      LCD.refresh();
//      jalan("" + arah);

    } catch (Exception e) {
View Full Code Here

                            '0', '0', '0', '0'
                        };
                        byte[] pin = enterNumber(4, "PIN for " + btrd.getFriendlyName(false), tempPin); // !! Assuming 4 length
                        if (pin == null) break;
                        LCD.drawString("Please wait...", 0, 6);
                        BTConnection connection = Bluetooth.connect(btrd.getDeviceAddr(), 0, pin);
                        // Indicate Success or failure:
                        if (connection != null)
                        {
                            LCD.drawString("Paired!      ", 0, 6);
                            connection.close();
                        }
                        else
                        {
                            LCD.drawString("UNSUCCESSFUL  ", 0, 6);
                            Bluetooth.removeDevice(btrd);
View Full Code Here

   * into a BTConnection object. However, how to pull information
   * from it, such as friendly name, address, etc... ??
   * Solution: Add address to BTConnection class?
   */
  public static RemoteDevice getRemoteDevice(Connection conn) throws IOException {
    BTConnection btc = (BTConnection)conn;
    return new RemoteDevice(btc.getAddress());
  }
View Full Code Here

    if (partner == null) {
      LCD.drawString("partner tidak ketemu", 0, 4);
      LCD.refresh();
      return false;
    }
    BTConnection btc = Bluetooth.connect(partner);
    if (btc == null) {
      LCD.drawString("tidak bisa nyambung", 0, 5);
      LCD.refresh();
      return false;
    }
    LCD.drawString("Mulai mengirim", 0, 6);
    LCD.refresh();
    DataOutputStream dos = btc.openDataOutputStream();
    for (int i = 0; i < pesan.length(); i++) {
      char a = pesan.charAt(i);
      LCD.drawString("Yang dikirim " + a, 0, 2);
      dos.writeChar(a);
      // dos.writeInt(a);
      dos.flush();
    }
    dos.writeChar('e');
    dos.flush();
    dos.close();
    LCD.drawString("Selesai mengirim", 0, 7);
    btc.close();

    return true;
  }
View Full Code Here

  private static void connect() {
    try {
      LCD.drawString("Menunggu koneksi", 0, 0);
      LCD.refresh();
      BTConnection btc = Bluetooth.waitForConnection();

      DataInputStream dis = btc.openDataInputStream();

      LCD.drawString("Sudah dapat koneksi", 0, 1);
      LCD.refresh();

      int read = dis.readInt();
      String arah = "";

      LCD.drawString("Pesan : " + read, 0, 2);
      LCD.refresh();

      while (read != 8) {
        // Ambil semua petunjuk arah dari Hayate sampai karakter
        // sentinel
        arah += read;
        read = dis.readInt();
      }

      dis.close();
      btc.close();
      LCD.drawString("Arah " + arah, 0, 0);
      LCD.refresh();
      jalan("" + arah);

    } catch (Exception e) {
View Full Code Here

TOP

Related Classes of lejos.nxt.comm.BTConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.