57

After using RXTX for a number of different projects, I've come across many annoying discrepancies and issues that can only sensibly be put down to bugs in the library - deadlocks, race hazards, and monitor threads deep in the RXTX library being left open preventing the program from closing (even though all ports I was using have been closed!) Running the latest "unstable" version has helped a bit, but it's still far from where I'd call it reliable, and activity on the project seems rather low at present.

However, searching for free cross-platform alternatives to RXTX doesn't seem to come up with much else.

Is there another library that anyone's tried with more luck? I don't need parallel port support, just serial, and it doesn't necessarily have to be compatible with RXTX or the javax.comm API.

Michael Berry
  • 70,193
  • 21
  • 157
  • 216
  • 8
    The new 2.5.0 version of jSSC library is available, it contains some important fixes, and is strongly recommended to update. For more information see: https://code.google.com/p/java-simple-serial-connector/ – scream3r Apr 29 '13 at 12:25
  • 1
    I am currently experiencing the same problems as you ... always errors inside the libraries, deadlocks whereas you are careful enough to close all the ports correctly ... It is really annoying. Really consider other options . – Mxsky May 06 '16 at 12:21
  • 1
    @Mxsky FWIW, jssc (linked below) has worked well for me since :) – Michael Berry May 08 '16 at 23:11
  • 2
    Did you tried this? https://github.com/Fazecast/jSerialComm – hurelhuyag Jun 10 '20 at 14:44
  • 2
    My vote would be for jSerialComm. We've used this reliable over RXTX in our serial apps. The lack of a native component to maintain is a big plus. – simgineer Sep 16 '21 at 19:46

7 Answers7

47

We have moved to java-simple-serial-connector which seems to be very stable and comfortable at the current release 0.9.0. For now, it works on windows and linux systems. We use it for modem interactions.

Alexey Shmalko
  • 3,678
  • 1
  • 19
  • 35
sebastian
  • 2,427
  • 4
  • 32
  • 37
  • 2
    This seems to be doing the job well for the moment (and appears to contain the native libraries it needs within, another plus.) Thanks! – Michael Berry Sep 11 '12 at 13:26
  • 2
    We had some issues with RxTx on an ARM hardware running JamVM, especially regarding the CPU. A test program that uses blocking calls with receive timeout and threshold set ran on 15-30% CPU which multiplies when using multiple ports. Now, jssc doesn't provide the setting of thresholds so I implemented it using the event API. However, both the event API and also the read methods with timeout paramter make use of busy loops (Thread.sleep) which, on out target made it even worse: We've had 100% CPU running communication on one serial port! – jaw Sep 17 '14 at 07:48
  • @jaw same problem here on arm, the native libraries of RXTX are polling the port for events and drawing a lot of CPU. Add to the fact I have multiple serial ports to monitor it's really straining the resources and increasing system latency. – darkhelmet Jan 17 '18 at 16:44
  • Even though the library has not been updated for more than 5 years, it does a good job to do simple tasks. It can be used to communicate with arduino and its much simpler and convenient than RxTx. – lepe Feb 21 '19 at 04:46
  • 1
    The latest version (2.8.0, 6 years old as of writing) crashes every 14 days – Mark Jeronimus Nov 18 '19 at 10:14
20

There's jSerialComm too.

Serial communication in Java is a mess. I've had trouble with jSSC with a virtual usb serial on linux, but with serial-comm it connected.

RXTX is a mess.

At least I think that now this SO question has all of the worth mentioning serial communication java libraries.

miguelcobain
  • 4,734
  • 4
  • 32
  • 45
  • +1 for serial-comm. Just been checking it out after getting fed up with the hideous mess that is RXTX. Serial-comm, by contrast, is clean and well-documented. I just pulled out RXTX and integrated serial-comm into my project in about half an hour. Lovely. – davidf2281 Feb 24 '15 at 13:30
  • +1 for the jSerialComm, easy to integrate, without requiring external libraries or any native code. You don't care a lot about wheather your OS is 32 or 64-bit – Ahmed MANSOUR Aug 13 '18 at 08:27
  • 1
    +1 for jSerialComm. We use this in our industrial applications, it is reliable and better packaged than RXTX. maybe the name of the library should be renamed to jSerialComm to avoid confusion, another person added another answer with the same recommendation. – simgineer Sep 16 '21 at 19:41
  • @simgineer I updated the library name, thank you. – miguelcobain Sep 22 '21 at 00:24
  • JSerialComm has bugs on listeners – Oumalek Mohamed Aug 29 '22 at 20:01
5

There's a few of them out there now, now that Arduino is pretty popular.

There's Serialio

and PureJavaComm, but it's pretty early on in development from what I can see.

it really depends on what your needs are. RXTX has been ported pretty much everywhere, so it is widely available.

Mike
  • 3,186
  • 3
  • 26
  • 32
  • 8
    SerialIO appears to be a commercial product that cost$ big buck$. Boo! – ingyhere Mar 21 '13 at 08:23
  • PureJavaComm is very good (and free). I've used it for serial communications for a few years now and found it to be very robust. – Jason S Apr 15 '17 at 21:43
2

One of the issues of RXTX I faced was the delay closing the port. When checking with setserial the port configuration I discovered a parameter closing_delay=3000. This means that the port closes 3 sec after the close() method was executed. Resetting the closing_delay toany value is ignored by RXTX. RXTX insists in 3sec delay.

the JSSC library performed to our satisfaction

sjpapa
  • 41
  • 2
1

Serialio lib is $49/platform/developer seat which gets you unlimited distribution in unlimited apps so not too pricey. The Mac library has been stable and reliable for us in an undemanding application and availability/compatibility has been good throughout for the various Mac platforms and OS/X releases.

1

I use socat configured to serve a socket for a serial port. The downside is that baud rate etc. is given to the socat invocation, it is not something you can readily alter from your program. On the upside is I can connect across a network without anything more than changing the IP address I connect to.

1

jSerialCom is good ! 'https://github.com/Fazecast/jSerialComm'

And here is its' wiki page: https://github.com/Fazecast/jSerialComm

James Wang
  • 31
  • 8
  • Miguelcobain's answer suggest the same library although he called it something different. – simgineer Sep 16 '21 at 19:43
  • "maybe the name of the library should be renamed to jSerialComm to avoid confusion"!I don't know his mean: 'jSerialComm' should be renamed to 'jSerialComm' ? – James Wang Mar 02 '22 at 07:55
  • The original answer referred to jSerialComm under a different name, it has since been corrected so the mention of incorrect name can be confusing. – simgineer Mar 03 '22 at 16:03