33

I've been looking around for a Java API that can communicate with serial devices on Windows/Win32 but many of the APIs I've checked out are either for Linux, too outdated, or just had bad critics.

Can someone recommend one to me that they've tried or knows about that is easy to implement on Windows XP?

dsolimano
  • 8,870
  • 3
  • 48
  • 63
Steve
  • 1,955
  • 9
  • 28
  • 30

5 Answers5

16

I started looking for the same thing couple weeks ago, and I've been very happy with the multi-platform RXTX library so far. Works with any Windows, Linux and OS X. Has a very clean, easy to understand API.

edit: RXTX is also open source.

Murat Ayfer
  • 3,894
  • 6
  • 29
  • 26
  • 2
    The quality of the RXTX code is quite bad. Be prepared to jump through various hoops if you go down this road. – Gili May 21 '09 at 07:34
  • 1
    it's not bad for most simple things. I'm running into issues on USB comm ports under abnormal circumstances (e.g. USB gets plugged in / unplugged at runtime). – Jason S Jan 26 '10 at 22:16
8

Without reservation, I recommend Java Serial Port from serialio.com; I had significant stability problems with the Sun, IBM and RxTx serial package. SerialPort has been rock solid in production 24/7 for over 5 years.

They support the standard Java serial API, as well as their own alternative proprietary one. I would stick with the standard API though, unless you really need something theirs has that the standard one doesn't, just to keep your options open.

Lawrence Dol
  • 63,018
  • 25
  • 139
  • 189
7

I've been using PureJavaComm for the last five years or so. It's actively maintained, and is a pure Java (via JNA) implementation. RXTX has let me down because of a lack of maintenance and numerous subtle problems.

Jason S
  • 184,598
  • 164
  • 608
  • 970
3

Java is notorious for its flaky serial I/O support. At a previous job, we tried both RXTX and SerialIO for an application that streamed data at 56kbps from a Teknic servo controller, and found them to gobble up the CPU quite a bit. Perhaps for apps that don't require continuous streaming from a serial port, both of these libraries are good, but we didn't feel that streaming I/O from a serial port should be eating a sustained 15-30% of the CPU on the machine when it is much needed for other threads in the JVM that need to be responsive.

Instead, we created a server in C++ that would read the stream of data from the serial port on the servo, transform/packetize it and send it to our Java app in XML over a socket connection. The CPU load on the serial I/O server in C++? Barely creeping into 1% at its worst.

There are certain things Java does well - serial I/O, in my opinion, isn't one of them, depending on the type of application...

Ultimately, you should take even what I said with a grain of salt, and try both, RXTX and SerialIO (which is dirt cheap, like $50 or so for the java version) and if they meet your needs, go with it. Personally, I'd stick with SerialIO because it is supported and actively worked on. RXTX, not so much.

  • 5
    I fear you blundered somewhere your code; I wrote a multi-modem serial to TCP/IP bridge in Java and it easily kept 16 ports streaming 56K without even breaking double digits in CPU on a modest circa 2005 desktop PC (using a RocketPort serial controller), and 4 ports comfortably on similar hardware using built-in serial ports. All with a full GUI showing real-time activity on the ports. – Lawrence Dol Apr 26 '13 at 00:40
  • 1
    I agree. SerialIO Serial Port is inexpensive, it support multiple platforms and you get the source code. The only drawback I can think of is that Linux (and BSD) x64 are still not supported. – Jarek Przygódzki Mar 17 '14 at 14:21
2

I've written an open-source Java library because none of the existing ones fit my needs (outdated, closed-source, hard to modify, un-maintained, ...).

It's called JSerial, it's MIT-licensed, and you can learn more here: https://github.com/thibautd/JSerial !

Currently only supports Windows, but I have plans for supporting Linux. You can easily modify the native part with the latest Visual Studio if you need.

Thibaut D.
  • 2,521
  • 5
  • 22
  • 33