By Jim Connors-Oracle on Jun 20, 2014
Last touched upon in this article dated August 2011, it's high time to revisit the state of Java serial port communications options for the following reasons:
- As the hype around Internet of Things continues to ratchet up, serial communications are a requirement for a certain class of IoT sensors and devices.
- RxTx, the platform with arguably the most history, cannot be built with the recently released Java 8 JDK without some modifications.
- For some time now the website hosting the RxTx project: http://rxtx.qbang.org/wiki/index.php/Main_Page has not been available.
- Building support for additional specifications like RS-485 and parallel is available in RxTx but was never addressed in the previous serial communications article.
- An alternative framework called jSSC is gaining in popularity and is worth further discussion.
- Work in the OpenJDK Device I/O Project is progressing. Among the goals of this project is support for serial communications.
In my customer experiences, RxTx, despite its age, still gets mentioned most when considering serial communications with Java. For whatever reasons, the RxTx project has gone off line, and access to the project source code is not readily available. Fortunately, we have a copy, and have made a few enhancements such that:
- The source can now be compiled with a JDK versions 6, 7 and 8.
- The original article discussed only enough modifications to build the librxtxSerial.so shared object required for traditional serial communications. The librxtxParallel.so, librxtxRaw.so, librxtxI2C.so and librxtxRS485.so shared objects could not be built. With some very slight modifications, these can successfully be built too. I make absolutely no promises as to their usefulness, but they do compile. :)
The source code is based upon the original 2.1-7r2 version and in this instance is now called 2.1.7r2-Java8. You can download the source here. If you want to get a feel for the changes made, take a look at this file: JAVA8_MODS.txt which can be found in the main directory of the source code. To build RxTx on your native platform:
$ tar xvf 2.1.7r2-Java8.tar.gz $ cd 2.1.7r2-Java8/ $ ./configure $ make
The Java Simple Serial Connector, or jSSC for short, is another open source project that can be found here: http://code.google.com/p/java-simple-serial-connector/. It is available for a host of processor/OS combinations and, in addition to source availability, comes bundled in binary form too. Here's a list of supported platforms for its current 2.6.0 release:
Win32 Win64 Linux_x86 Linux_x86_64 Linux_ARM Solaris_x86 Solaris_x86_64 MacOSX_x86 MacOSX_x86_64 MacOSX_PPC MacOSX_PPC64
Like RxTx, it contains a native component but is packaged in a nice transparent fashion. The one potential challenge here may be in trying to figure out how to support a new platform that isn't on this list. I didn't have a whole lot of success finding out how to build the binary, and admittedly didn't spend an inordinate amount of time trying to figure it out either. Nonetheless, this project is gaining in popularity and has a dedicated individual supporting the software.
OpenJDK Device I/O
Finally, a project is underway to treat serial communication and device I/O in general as a first class citizen for the Java SE standard. The wiki can be found here: https://wiki.openjdk.java.net/display/dio/Main. It is based on the work done to provide device I/O to the Java ME 8 platform. Further solidifying the universality theme of Java 8, the ultimate goal would be to have a consistent device I/O API across both Java SE and Java ME. If you want to further understand what those APIs look like you can view them here: http://docs.oracle.com/javame/8.0/api/dio/api/index.html.
In conclusion, support for serial communications in Java SE is -- albeit slowly -- progressing. There are multiple open source projects and commercial alternatives too. Ideally, it will be great to see a formal API supported by the Java SE Standard.