The need to communicate with devices connected to serial ports is a common application requirement. Falling outside the purview of the Java SE platform, serial and parallel port communication has been addressed with a project called RXTX. (In the past, you may have known this as javacomm). With RXTX, Java developers access serial ports through the RXTXcomm.jar file. Alongside this jar file, an underlying native layer must be provided to interface with the operating system's UART ports. For the usual suspects (Windows, Linux/x86, MacOS, Solaris/Sparc), pre-compiled binaries are readily available. To host this on an alternative platform, some (hopefully minimal) amount of work is required.
Here's hoping the following notes/observations might aid in helping you to build RXTX for an embedded device utilizing one of our Java SE Embedded binaries. The device used for this particular implementation is my current favorite: the Plug Computer.
Notes on Getting RX/TX 2.1-7-r2 Working on a Plug Computer
1. At this early juncture with Java 7, be wary of mixing Java 7 with code from older versions of Java. The class files generated by the JDK7 javac compiler contain an updated version byte with a value that results in older (Java 6 and before) JVMs refusing to load these classes.
2. The RXTX download location http://rxtx.qbang.org/wiki/index.php/Download has binaries for many platforms including Arm variants, but none that worked for the Plug Computer, so one had to be built from source.
3. Using the native GCC for the Plug Computer and the RXTX source, binaries (native shared objects) were compiled for the armv5tel-unknown-linux-gnu platform.
4. The RXTX "stable" source code found at the aforementioned site is based on version rxtx 2.1-7r2. This code appears to be pretty long in the tooth, in that it has no knowledge of Java 6. Some changes need to be made to accommodate a JDK 6 environment. Without these modifications, RXTX will not build with JDK6
SUGGESTED FIX, most elegant, not recommended:
Edit the configure.in file in the source directory and look for the following:
case $JAVA_VERSION in
1.2*|1.3*|1.4*|1.5*)
and change the second line to:
1.2*|1.3*|1.4*|1.5*|1.6*)
Upon modification, the autogen.sh script found in the rxtx source directory must be re-run to recreate the ./configure script. Unfortunately, this requires loading the autoconf, automake and libtool packages (plus dependencies) and ended up resulting in libtool incompatibilies when running the resultant ./configure script.
RECOMMENDED FIX:
Instead, edit ./configure and search for the occurrences (there are more than one) of
case $JAVA_VERSION in
1.2*|1.3*|1.4*|1.5*)
and change the second line to:
1.2*|1.3*|1.4*|1.5*|1.6*)
Run './configure', then 'make' to generate the RXTXcomm.jar and platform specific .so shared object libraries.
5. You may also notice in the output of the make, that there were compilation errors for source files which failed to find the meaning of "UTS_RELEASE". This results in some of the shared object files not being created. These pertain to the non-serial aspects of RXTX. As we were only interested in librxtxSerial.so, this was no problem for us.
6. Once built, move the following files into the following directories:
# cd rxtx-2.1-7-r2/
# cp RXTXcomm.jar $JAVA_HOME/lib/ext
# cd armv5tel-unknown-linux-gnu/.libs/
# cp librxtxSerial-2.1-7.so $JAVA_HOME/lib/arm
# cd $JAVA_HOME/lib/arm
# ln -s librxtxSerial-2.1-7.so librxtxSerial.so
Now Java applications which utilize RXTX should run without any java command-line additions.
The RXTXcomm.jar file can be downloaded here. To spare you the effort, a few pre-built versions of librxtxSerial-2.1-7.so are provided at this location:
If you've gone through this exercise on any additional architectures, send them my way and I'll post them here.
Many thanks for including the compiled library, that saved me a huge headache.
Thanks Jim,
Worked a treat... compiled nicely for armV7l (tegra2). Well... a few warnings and errors came up but it worked! i can send you the .so and .jar files if you like to make them available for this architecture.
- Dan.
By all means! You supply the binaries and I'll post them.
i am new to this can you please guide me how to use thisi need to send data through rs232 from pc
Gary Collins recently got his hands on one of the much ballyhooed Raspberry Pi devices, and was kind enough to provide the native librxtxSerial.so share object for this armv6l based platform. It is now listed as one of the provided pre-build versions.
Thank you for compiled library. Now I am able to combine my electronics with Qnap (environment temperature reporter). Greetings.
Hello,
I have tried the librxtxSerial-2.1-7.so for ARMv6l based systems (e.g. Raspberry Pi), on my Raspberry Pi running OpenJDK 1.6 on Arch Linux
Unfortunately, I don't believe it has the fix. I get "java.lang.UnsatisfiedLinkError: gnu.io.RXTXCommDriver.nativeGetVersion()Ljava/lang/String; thrown while loading gnu.io.RXTXCommDriver" which would be the message I believe if the .so did not have the fix.
Your problem may lie in the fact that the Raspberry Pi Arch Linux distro uses the armhf (hard float) ABI which is incompatible with the armel-based version of the librxtxSerial.so which was originally provided here. I've been patiently waiting and just received my very own Raspberry Pi. When I get a chance, I'll try compiling an armhf version under the Raspbian (armhf) distro.
Updated to include librxtxSeirial-2.1-7.so files for both armel and armhf based Raspberry Pi distributions.
Has anyone compiled and tested rxtxlib for the BeagleBone? I tried pre-built versions ARMv6 for armhf and it works 3 hours when crashed. This happened repeatedly.
I would be very happy if somebody upload version that fits to BeagleBone.
For Linux why not use socat and then use sockets from Java ?
http://dollopofdesi.blogspot.it/2011/07/routing-serial-data-to-socket.html
I posted earlier that rxtxlib with BeagleBone crashed within 3 hour use. I have found out that problem didn't focused on rxtxlib. Reason came up from Huawei E367 netstick that is used as dial-up modem. This device seems not not to be so reliable.
Running RXTX as an OSGi bundle allows to dynamically choosing the right native lib to load based on system properties (see OSGi "Bundle-NativeCode" manifest tag).
Unfortunately, running the Oracle JVM 1.7.0 does not allow to distinguish the version of the ARM processor (V.5/6/7) using the system propertie. The "os.arch" is just "arm". Also, for ARMv6 (Raspberry Pi), it should be possible to distinguish between HF and SF.
How can the dynamic choice of the native lib be done?
This is currently not an easy problem to solve. Ironically I wrote a related blog entry entitled "Is it armel or armhf?". In there you'll find a pointer to a Raspberry Pi forum entry which discusses your exact question.
the website http://rxtx.qbang.org/ is not available now. anybody know how to download the native source ?
Been meaning to do this for a while, check out this blog entry:
Java Serial Communications Revisited
https://blogs.oracle.com/jtc/entry/java_serial_communications_revisited
Among other things it points to RxTx source code with some very minor modifications.
please add tag "raspbian" and "raspberry pi"
thanks :)
Done. Added "raspbian" and "raspberry-pi" tag to this blog and the preferred, updated version - https://blogs.oracle.com/jtc/entry/java_serial_communications_revisited
Can you provide librxtxSerial.so for armv8
Check out this later blog on serial communications: https://blogs.oracle.com/jtc/entry/java_serial_communications_revisited
In the article, the source code is provided with some modifications such that it should readily build on your platform.
https://blogs.oracle.com/jtc/updates-to-java-serial-communications-raspberry-pi-3-v2
points to a git repository which contains an AMRv7l build.
https://github.com/jtconnors/rxtx-2.1-7r2
Note: this was done a few years ago, so I have no idea if it's still relevant
I use a raspberry pi with software that required it, and this was AWESOME because it works on the pi3b+. With the 4 released I was considering upgrading hardware, but it doesn't look promising.
Thank you!
https://github.com/jtconnors/rxtx-2.1-7r2-binaries
I'm not sure if there's a match for the latest Raspberry Pi 4 architecture. If not, if I could get my hands on one, I'd try creating a new build.
I would pay for a pi 4b+ compatible version...