Java Serial Communication on Windows

后端 未结 5 1786
有刺的猬
有刺的猬 2020-12-01 07:46

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,

相关标签:
5条回答
  • 2020-12-01 08:05

    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.

    0 讨论(0)
  • 2020-12-01 08: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.

    0 讨论(0)
  • 2020-12-01 08:17

    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.

    0 讨论(0)
  • 2020-12-01 08:20

    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.

    0 讨论(0)
  • 2020-12-01 08:26

    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.

    0 讨论(0)
提交回复
热议问题