Java Serial Communications Revisited

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.

RxTx

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

jSSC

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.

Comments:

Hello, i have using the original library in my implementations, but i lost this files. I tried to use your library but i got an error on my platform (CentOs 6.5). It is possible to give me the original files (qbang's rxtx). ?. Thanks and regards.

Posted by Ivan Pozo on July 16, 2014 at 03:31 PM EDT #

Hi Ivan,

I only have the original source for rxtx-2.1-7r2 and have placed it here:

https://blogs.oracle.com/jtc/resource/rxtx-2.1-7r2-Java8/rxtx-2.1-7r2.zip

-- Jim C

Posted by Jim Connors on July 17, 2014 at 09:45 AM EDT #

Another cross-platform library we use is SerialIO's SerialPort library. It is effective and robust but it has several problems. (1) it is only supported for 30-90 days after purchase, (2) most support enquiries receive the grumpy response "modify the source and recompile it yourself", (3) it must be re-purchased every time there is a new platform (e.g. Windows 8, Windows 8.1), (4) it is expensive to re-buy each time especially with source included and (4) it doesn't include any Linux ARM binaries at all (eg. for Raspberry PI) - fiddling about with the source to achieve this is not something we're willing or able to do.

Posted by Myk on November 06, 2014 at 10:50 PM EST #

sir i am communicate plc to java. those library use can communicate to plc machine. pls sir help me..then suggest me..

Posted by Mayur Patil on December 02, 2014 at 01:54 AM EST #

If you wish to comminucate via Java with a PLC and that PLC supports serial commuinication, then yes you should be able to use either the RxTx or jSSC libraries.

Posted by Jim Connors on December 02, 2014 at 01:23 PM EST #

sir i have communicate to messung plc. but those plc not available Ethernet port only rs232/485 port available. my project to monitoring the plc to use java lang. i have use converter rs232 to usb . those converter use possible connecting the plc to laptop. then can possible use converter monitor to plc to java lang. pls suggest me..

Posted by Mayur Patil on December 10, 2014 at 12:14 AM EST #

Hi Mayur,

I recently blooged about using javahidapi as a means to communicate, via Java, to a USB device. In this instance the device was a USB temperature sensor, but javahidapi should hopefully be flexible enough for serial port communcation too.

Check out https://blogs.oracle.com/jtc/entry/simplifying_usb_access_for_java which pointo to the javahidapi project: http://code.google.com/p/javahidapi/

Posted by Jim Connors on December 11, 2014 at 10:26 AM EST #

Any experience/thoughts about serilio.com's SerialPort (product) for Java?

Posted by guest on December 24, 2014 at 08:52 AM EST #

Heard about them, but never used it. I have no reason to believe that it isn't a very effective platform, Just looking at pricing, a 1000-seat license costs $9995 USD which amounts to a $10 per-seat cost. On embedded systems, the per-seat cost of deploying a JRE is likely to be less. Seems without discounting to be a pricy addition.

Posted by Jim Connors on December 26, 2014 at 09:36 AM EST #

My bad. The 100 user per-seat cost (list price) is $995, which is a lot more reasonable. What I do find annoying though is that they charge for development seats.

Posted by Jim Connors on December 26, 2014 at 09:44 AM EST #

Just compiled your newest version of rxtx, deployed on an Atom processor (i386) Shuttle computer running Arch Linux. Java version 1.7.0_71. Works fine. Thanks for doing this.

Posted by guest on January 14, 2015 at 07:42 PM EST #

Repository : https://github.com/RishiGupta12/serial-communication-manager
Wiki : http://www.embeddedunveiled.com/scm-wiki

The 'serial communication manager (scm)' is a java library designed and developed to exchange data on serial port. It supports RS-232 control signals handshaking, monitoring and has been ported to Linux, MAC, Solaris and Windows operating system. It is consistent, scalable, testable, efficient, reliable and portable.

Posted by guest on March 26, 2015 at 05:41 AM EDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Jim Connors-Oracle

Search

Categories
Archives
« May 2015
SunMonTueWedThuFriSat
     
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
      
Today