1 import lejos.pc.comm.*;
6 public static void main(String[] args) {
7 NXTComm nxtComm = NXTCommFactory.createNXTComm(NXTCommFactory.BLUETOOTH);
9 /* Another way to connect, by discovery:
11 NXTInfo[] nxtInfo = nxtComm.search(args[0], NXTCommFactory.BLUETOOTH);
13 if (nxtInfo.length == 0) {
14 System.out.println("No NXT Found");
19 // arg[0] = name, e.g NXT
20 // arg[1] = address, with optional colons, e.g. 00:16:53:00:78:48
22 if (args.length != 2) {
23 System.out.println("Usage: BTSend name address");
27 NXTInfo[] nxtInfo = new NXTInfo[1];
29 nxtInfo[0] = new NXTInfo(args[0],args[1]);
31 System.out.println("Connecting to " + nxtInfo[0].btResourceString);
33 boolean opened = nxtComm.open(nxtInfo[0]);
36 System.out.println("Failed to open " + nxtInfo[0].name);
40 System.out.println("Connected to " + nxtInfo[0].btResourceString);
42 InputStream is = nxtComm.getInputStream();
43 OutputStream os = nxtComm.getOutputStream();
45 DataOutputStream dos = new DataOutputStream(os);
46 DataInputStream dis = new DataInputStream(is);
48 for(int i=0;i<100;i++) {
50 dos.writeInt((i*30000));
52 } catch (IOException ioe) {
53 System.out.println("IO Exception writing bytes");
57 System.out.println("Received " + dis.readInt());
58 } catch (IOException ioe) {
59 System.out.println("IO Exception reading bytes");
65 //dos.close(); Why does this prevent re-connection?
67 } catch (IOException ioe) {
68 System.out.println("IOException closing connection");