Java–Serial Killer

Its about time a public mourning took place for people who are allergic to coffee…

Although I do feel pity for the people who are allergic to coffee (what a horrible existence… i would hate not being able to have the best addiction)  this is not the topic of this post.

Ahhh so are you taking about the mass deprecation that takes place in Java?

Although the deprecation of components in Java does annoy me (Java 7 Deprecations, J6 Deps) it is a necessity in most cases  but this is not the choice of topic.

I get it, you are taking about all the nuclear facilities that had faulty Java control software in place which caused a meltdown or 2!!

Eh no, the java agreement requires that “You acknowledge that Licensed Software is not designed or intended for use in the design, construction, operation or maintenance of any nuclear facility”

Im taking about the state of communicating with RS232 devices from Java.

That’s simple just use java.comm

Exactly what I thought too but it appears that the write once run anywhere promise of Java has been broken further, back in the day it was possible to write windows Java apps that could use Java.comm but it appears that it is no longer possible to use this functionality outside of Linux, Mac OS X and Solaris.

I recently discovered this when I developed a web service component that uses a RS232 sensor on linux where it worked fine and I was a happy coder but when I brought it over to windows I was left astonished and searching for a solution.

RXTX to the rescue

After doing some searching around I found a beautiful LGPL product called rxtx which provides platform agnostic RS232 support through a native library and jar class file combination.

The native library goes into the the /bin sub folder of both the Java runtime and Development Kit folders and the .jar file goes into the companion /lib subfolders of those directories.

The API is easy to use and clear with a fairly logical structure for example to detect COM ports on a system the following code fragment is used

 1: List <String> list = new ArrayList<String>();
 2: Enumeration portList = CommPortIdentifier.getPortIdentifiers();
 4: while (portList.hasMoreElements()) {
 6:      CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
 8:      if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
 10:           list.add(portId.getName());
 11:      }
 12: }

The rxtx project lives at where you can get a variety of downloads and a wealth of documentation


  1. Louis Vuitton Monogram Canvas
    July 2, 2012 - 09:28

    Thank you using the good writeup. By the way, how could we communicate?

Leave a Reply

Your email address will not be published / Required fields are marked *


Please type the text above: