See:
Description
| Packages | |
| rcx | Provides classes and interfaces for handling and supporting communication with the Lego Mindstorms RCX (versions 1.0 and above) These classes use the Java Communications API for communicating via the serial port (for RCX version 1.0 or 1.5) as well as the USB port (RCX 2.0 and above) by using the rcx.comm package In addition to supporting these ports, the architecture abstracts the ports to allow for new types of RCX ports such as a TCP socket port for remote communication and a high level abstraction to motors, sensors and sounds An emulation mode is also available for developing and testing without an RCX. |
| rcx.comm | Provides classes and interfaces for handling and supporting the USB port on various platforms for the Lego Mindstorms RCX tower (version 2.0+) These classes abstract the underlying native USB drivers and provides a mechanism similar to the Java Communications Extension API for discovering and managing USB Ports. |
import rcx.*;In the example above the port name is passed from the command line. The port name is the name of the actual port. For example, on the Windows platforms this would be COM1 to indicate a serial port or LEGOTOWER1 to indicate a USB port.
public class Test {
public static void main(String[] arg) {
new Test(arg[0]);
}
public Test(String portname) {
RCXPort port = new RCXPort(portname);
Motor.A.forward();
Motor.A.stop();
port.beep();
System.out.println(
"Battery Level = "+port.getBatteryPower()+" volts.");
}
}
In addition to these two types of RCX ports, polymorphism is demonstrated further by passing in a custom port name for remote control via sockets as shown in the advanced example below. One can reuse the same exact code to run in a standalone application or in a remote applet. In the following case the same AWT panel, RCXControl.java, can be used in an application where the port name is supplied via the command line, RCXControlApp.java, or in an applet, RCXApplet.java, where the port name is provided on the html page via an applet tag parameter.
<applet codebase="." code=RCXApplet.class archive=rcx.jar width=275 height=125>The following screen shot shows the applet in a browser:
<param name=rcxport value="rcx://localhost:174">
</applet>
![]()
To run this example the proxy server provided by the RCX Java library is required:
java -cp rcx.jar rcx.RCXServer [portname] [portnumber]
Where portname is the name of the local rcx port (e.g. COM1 or LEGOTOWER1) and port number is the server port number that the applet client connects to (default value is 174). To run the client open test.html which is provided in the distribution.
For more documentation please refer to the javadoc documentation for the RCX Java API.
For further information on the history, architecture and design considerations of the RCX Java API, a detailed analysis of the Java Communications API with the trials and tribulations of extending that API (why it is no longer possible or supported) as well as the design considerations when adding USB support, refer to the following book now available:
Programming Lego Mindstorms with Java![]()
Publisher: Syngress Publishing
ISBN: 1-928994-55-5
Not only is the RCX Java API covered but several other Java APIs for the RCX including leJOS which is a custom Java VM that can run inside the RCX, allowing you to run Java tasks inside the RCX.
The accompanying CD contains all the required software including additional example code for the RCX Java API (e.g. using AI with RCX robots).
This documentation is also available in the zip file distribution.
It was generated using the javadoc utility of the Java 2 SDK 1..4.0