Page 242 - The Ultimate Palm Robot
P. 242
Color profile: Generic CMYK printer profile
Composite Default screen
Bots /The Ultimate Palm Robot/ Mukhar & Johnson / 222880-6 / Chapter 8
Chapter 8 Taking Control of the BrainStem Robot 225
3. Add comm.jar to your classpath.
4. Copy the file javax.comm.properties to the same directory where
you copied comm.jar.
5. Make sure you have the JDK native thread package installed.
This implementation only works with native thread. Look at
http://java.sun.com/products/jdk/ for details.
You are now ready to write Java programs that can communicate to other
devices over the serial port.
Java and the BrainStem
Luckily for us, Acroname has already developed some base classes that han-
dle some of the lower level communication details for us. The class files can be
found in the Java software that you can get from Acroname. The files will un-
pack into the \aJava directory of the BrainStem distribution. The helper
classes are located in the \aJava\acroname directory. There is an example
program, gp_example.java, in the \aJava directory that shows how to write a
Java program for the BrainStem.
Here, we’ll show you some excerpts from that sample program so you can
get an idea of how you can use the Acroname Java classes to communicate
with the BrainStem.
Within your class, there are two primary Acroname classes that you will use:
jStem and jGP. The gp_example.java files declares variables for these objects.
jStem stem;
jGP gp;
Within the constructor, an instance of jStem is created, and then a few lines
further, the jGP instance is created:
/* build a stem to provide packet protocol */
stem = new jStem();
//code not shown...
gp = new jGP(stem, moduleAddress); //moduleAddress is 2
P:\010Comp\Bots\880-6\ch08.vp
Monday, May 12, 2003 1:16:47 PM