1 import java.io.IOException;
\r
4 import lejos.nxt.comm.*;
\r
9 * Test of NXT to NXT Bluetooth comms.
\r
11 * Connects to another NXT, sends 100 ints, and receives the
\r
12 * replies. Then closes the connection and shuts down.
\r
14 * Works with the BTReceive sample running on the slave NXT.
\r
16 * Change the name string to the name of your slave NXT, and make sure
\r
17 * it is in the known devices list of the master NXT. To do this, turn
\r
18 * on the slave NXT and make sure Bluetooth is on and the device
\r
19 * is visible. Use the Bluetooth menu on the slave for this. Then,
\r
20 * on the master, select the Bluetooth menu and then select Search.
\r
21 * The name of the slave NXT should appear. Select Add to add
\r
22 * it to the known devices of the master. You can check this has
\r
23 * been done by selecting Devices from the Bluetooth menu on the
\r
26 * @author Lawrie Griffiths
\r
29 public class BTConnectTest {
\r
30 public static void main(String[] args) throws Exception {
\r
31 String name = "NXT";
\r
33 LCD.drawString("Connecting...", 0, 0);
\r
36 BTRemoteDevice btrd = Bluetooth.getKnownDevice(name);
\r
40 LCD.drawString("No such device", 0, 0);
\r
46 BTConnection btc = Bluetooth.connect(btrd);
\r
50 LCD.drawString("Connect fail", 0, 0);
\r
57 LCD.drawString("Connected", 0, 0);
\r
60 DataInputStream dis = btc.openDataInputStream();
\r
61 DataOutputStream dos = btc.openDataOutputStream();
\r
63 for(int i=0;i<100;i++) {
\r
65 LCD.drawInt(i*30000, 8, 0, 2);
\r
67 dos.writeInt(i*30000);
\r
69 } catch (IOException ioe) {
\r
70 LCD.drawString("Write Exception", 0, 0);
\r
75 LCD.drawInt(dis.readInt(),8, 0,3);
\r
77 } catch (IOException ioe) {
\r
78 LCD.drawString("Read Exception ", 0, 0);
\r
84 LCD.drawString("Closing... ", 0, 0);
\r
89 } catch (IOException ioe) {
\r
90 LCD.drawString("Close Exception", 0, 0);
\r
95 LCD.drawString("Finished",3, 4);
\r