OSDN Git Service

6618bc0bdaca407332cd50ad512a14f64f5e8435
[nxt-jsp/lejos_nxj.git] / nxtOSEK / lejos_nxj / samples / BTConnectTest / BTConnectTest.java
1 import java.io.IOException;\r
2 \r
3 import lejos.nxt.*;\r
4 import lejos.nxt.comm.*;\r
5 import java.io.*;\r
6 \r
7 public class BTConnectTest {\r
8         public static void main(String[] args) throws Exception {\r
9                 String name = "NXT";\r
10                 \r
11                 LCD.drawString("Try to connect...", 0, 0);\r
12                 LCD.refresh();\r
13                 \r
14                 BTRemoteDevice btrd = Bluetooth.getKnownDevice(name);\r
15 \r
16                 BTConnection btc = Bluetooth.connect(btrd);\r
17                 \r
18                 LCD.clear();\r
19                 LCD.drawString("Connected", 0, 0);\r
20                 LCD.refresh();\r
21                 \r
22                 DataInputStream dis = btc.openDataInputStream();\r
23                 DataOutputStream dos = btc.openDataOutputStream();\r
24                                 \r
25                 for(int i=0;i<100;i++) {\r
26                         try {\r
27                                 LCD.drawInt(i*30000, 0, 2);\r
28                                 LCD.refresh();\r
29                                 dos.writeInt(i*30000);\r
30                                 dos.flush();                    \r
31                         } catch (IOException ioe) {\r
32                                 LCD.drawString("Exception", 0, 0);\r
33                                 LCD.refresh();\r
34                         }\r
35                         \r
36                         try {\r
37                                 LCD.drawInt(dis.readInt(),0,3);\r
38                                 LCD.refresh();\r
39                         } catch (IOException ioe) {\r
40                         }\r
41                 }\r
42                 \r
43                 try {\r
44                         dis.close();\r
45                         dos.close();\r
46                         btc.close();\r
47                 } catch (IOException ioe) {\r
48                 }\r
49                 \r
50                 Button.ESCAPE.waitForPressAndRelease();\r
51         }\r
52 }\r