2 import lejos.rcxcomm.*;
\r
7 * Test of NXT emulation of the leJOS RCX RCXPort class.
\r
9 * Run the LLCSensorReader sample on the RCX, and the NXT
\r
10 * will read the raw sensor value of the sensor connected to
\r
13 * Requires a Mindsensors NRLink adapter connected to sensor
\r
14 * port S1 on the NXT.
\r
16 * @author Lawrie Griffiths
\r
19 public class RCXPortTest {
\r
21 public static void main(String[] args) throws Exception {
\r
23 RCXPort port = new RCXPort(SensorPort.S1);
\r
24 String reading = "Reading Sensor";
\r
25 String rcvd = "Received ";
\r
27 InputStream is = port.getInputStream();
\r
28 OutputStream os = port.getOutputStream();
\r
29 DataInputStream dis = new DataInputStream(is);
\r
30 DataOutputStream dos = new DataOutputStream(os);
\r
32 LCD.drawString(reading,0,0);
\r
34 int sendTime = (int)System.currentTimeMillis();
\r
35 for(int i=0;i<20;i++) {
\r
39 int n = dis.readShort();
\r
41 LCD.drawString(rcvd,0,1);
\r
42 LCD.drawInt(n,4,10,1);
\r
45 LCD.drawString("Time: ", 0, 2);
\r
46 LCD.drawInt((int)System.currentTimeMillis() - sendTime,6,6,2);
\r
48 Button.waitForPress();
\r
50 catch (Exception e) {
\r
51 LCD.drawString("Exception",0,7);
\r
53 Button.waitForPress();
\r