Help with the Java Communications API

Use this API to communicate with a serial port

Q: I need to append a 1,000-byte StringBuffer to a file. These characters are read by my SerialConnection (main program) class from the serial port. I cannot seem to find a mechanism in Java to do this. I need to be able to create a synchronized server thread that will access the string buffer in my SerialConnection while allowing the main program to perform the data-collection tasks. This server needs to process client requests for the data from the file. It also should be able to raise exceptions if for some reason a problem occurs during writing/reading to or from the file.

A:
First, you need to head on over to Sun’s “Java Communications API” page. The Communications API allows you to write platform-independent software that uses the serial port. Currently, you can get a port to Solaris and Windows from JavaSoft. If you need a port to another OS, just do a quick search; it is probably available.

Next, you’ll need to learn how to use the API. Start by reading “Java Gets Serial Support with the New javax.comm Package” by Shivaram Mysore and Rinaldo Di Giorgio (JavaWorld, May 1998). In this article, you’ll find an extensive discussion of the Communications API. After that, you’ll want to read “Opening Up New Ports to Java with javax.comm” by Chuck McManis (JavaWorld, September 1998), which chronicles McManis’s experiences implementing code that uses a serial port in Java on Windows 95.

For another perspective, take a look at Jonathan Knudsen’s “Exploring the Communications API with Lego Robots.” As the article title indicates, Knudsen uses the communications API to talk to robots built from Lego blocks.

If you need more information, go to and type the following phrase into the search box: “Java Communications API.” You’ll be surprised at the amount of information that is returned. If what you’re looking for isn’t in there, it probably does not exist.

Good luck!

Source: www.infoworld.com