This is the first "release" of this page and the rcxcomm package. Please help us improve the page and the software, by sending any comments and bug reports to: LEGO3 Team at DTU-IAU
The software is far from stable.
Here are some of the most important bugs:
IOException occurs on the RCX when sending big amounts
of data to the PC
The API documentation generated by JavaDoc can be found
here.
Download
The rcxcomm package is included in the following JAR file:
rcxcomm.jar.
The API documentation for rcxcomm:
javadoc.zip
A small sample
Below is the source files of a small sample program.
Both files have a .txt file type, which must be removed
when downloaded. To run the sample programs, rcxcomm must be available
from both the leJOS-environment and the environment where the servlets are
running. The easiest way is to extract the files from the jar into your working
directory.
SensorReader.java
Compile and download the SensorReader to the RCX. When pushing run,
the RCX will start waiting for a byte from the PC. The byte sent from the PC
indicates which sensor to read from. When a byte arrive the RCX reads the
raw value of the given sensor, and sends the value back to the PC.
import java.io.*;
import rcxcomm.*;
import josx.platform.rcx.*;
/**
* @author LEGO3 Team at DTU-IAU
*/
public class SensorReader {
public static void main(String args[]) {
RCXDataPort port = new RCXDataPort();
int sensorID, sensorValue;
try {
while (true) {
sensorID = port.getInputStream().read();
sensorValue = Sensor.readSensorValue(sensorID, 0);
try { // We have to wait because of a bug in the communication.
Thread.sleep(100);
} catch (InterruptedException iE) { }
LCD.showNumber(sensorValue);
port.getOutputStream().write(sensorValue/256);
port.getOutputStream().write(sensorValue%256);
port.getOutputStream().flush();
}
} catch (IOException ioE) {
LCD.showNumber(1111);
} finally {
port.close();
try {
Thread.sleep(1000);
} catch (InterruptedException iE) { }
}
}
}
comPort value on the third line, to match your
configuration, e.g. "COM1" or "/dev/ttyS0".
Start your servlet runner and open the JSP page in your browser. Submit the
form, and with a little luck, you should get a result back from the RCX.