Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

Help with the Java Communications API

Use this API to communicate with a serial port

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone

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.

AI haven't personally done any Java development dealing with serial connections. However, I know that you can do it.

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 http://java.sun.com 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!

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comments (1)
Login
Forgot your account info?

For WindowsBy furkankamaci on February 14, 2009, 9:04 amFor windows platform, do i need to use the api in that website?

Reply | Read entire comment

View all comments

Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources