I know there is a rcxcomm.jar package but I need help on how to use it. I need to be able to write to the RCX (I'm using RCX, NXJ would be the same) while it is listening for input, and once it gets the input (a 1, 2, or a 3), it will know how to process it (ie: move forward, move backward, write "Hello World" to the LCD) with "if" commands.
From the sample code given in the lejos download, I am given that this is how to write:
- Code: Select all
import josx.rcxcomm.*;
import java.io.*;
public class Write {
public static void main(String [] args) {
try {
RCXPort port = new RCXPort();
OutputStream os = port.getOutputStream();
os.write(123);
os.flush();
}
catch (IOException ioe) {
}
}
}
And this is how to read:
- Code: Select all
import java.io.*;
import josx.rcxcomm.*;
import josx.platform.rcx.*;
/** Very simple example of using RCXInputStream on the RCX
* Communicates with Write.java on the PC
* For 2-way communication use RCXPort
*/
public class Read {
public static void main (String [] args) throws IOException {
RCXInputStream in = new RCXInputStream();
LCD.showNumber(in.read());
try {
Thread.sleep(1000);
}
catch (InterruptedException e) {}
}
}
So I compile and run/download the Read program onto the RCX robot (I'm using RCX but I'm sure the method is the same for NXJ), and press "Run" on the robot so it should be reading (waiting for input), then I try downloading the Write program, while the Read is running on the robot, but the RCX unit is unresponsive, probably because it's running another program. How do I send things to the RCX device on command?
Please any help would be GREATLY!!! appreciated.
