Java Serial Communication on Windows

后端 未结 5 1803
有刺的猬
有刺的猬 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: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.

提交回复
热议问题