Windows 上的 Java 串行通信
我一直在寻找可以与 Windows/Win32 上的串行设备通信的 Java API,但我检查过的许多 API 要么适用于 Linux,要么太过时,要么只是受到了批评。
有人可以向我推荐一个他们已经尝试过或知道的可以在 Windows XP 上轻松实现的软件吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
几周前我开始寻找同样的东西,我对多平台 RXTX 非常满意到目前为止库。 适用于任何 Windows、Linux 和 OS X。具有非常干净、易于理解的 API。
编辑:RXTX 也是开源的。
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.
毫无保留地,我推荐来自serialio.com的Java SerialPort(另请参阅这篇博文); 我在使用 Sun、IBM 和 RxTx 串行软件包时遇到了严重的稳定性问题。 SerialPort 在 24/7 生产中已坚如磐石 5 年多了。
它们支持标准的 Java 串行 API,以及他们自己的替代专有 API。 不过,我会坚持使用标准 API,除非您确实需要他们拥有而标准 API 没有的东西,只是为了保持您的选择余地。
Without reservation, I recommend Java SerialPort from serialio.com (also see this blog post); 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.
在过去五年左右的时间里,我一直在使用 PureJavaComm 。 它得到积极维护,并且是纯 Java(通过 JNA)实现。 RXTX 由于缺乏维护和许多微妙的问题而让我失望。
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.
Java 因其不稳定的串行 I/O 支持而臭名昭著。 在之前的工作中,我们在一个应用程序中尝试了 RXTX 和 SerialIO,该应用程序以 56kbps 的速度从 Teknic 伺服控制器传输数据,发现它们会大量占用 CPU。 也许对于不需要从串行端口连续流式传输的应用程序来说,这两个库都很好,但我们不认为来自串行端口的流式 I/O 应该持续占用 15-30% 的 CPU当 JVM 中其他需要响应的线程非常需要该机器时。
相反,我们用 C++ 创建了一个服务器,它将从伺服器上的串行端口读取数据流,对其进行转换/打包,然后通过套接字连接将其以 XML 形式发送到我们的 Java 应用程序。 C++ 中串行 I/O 服务器上的 CPU 负载? 在最糟糕的情况下也勉强达到 1%。
Java 在某些方面做得很好 - 在我看来,串行 I/O 不是其中之一,具体取决于应用程序的类型......
最终,您甚至应该对我所说的持保留态度,并尝试一下RXTX 和 SerialIO(这非常便宜,java 版本大约 50 美元左右),如果它们满足您的需求,就使用它。 就我个人而言,我会坚持使用 SerialIO,因为它受到支持并且正在积极开发。 RXTX,没那么多。
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.
我编写了一个开源 Java 库,因为现有的库都不符合我的需求(过时、闭源、难以修改、无法维护……)。
它称为 JSerial,已获得 MIT 许可,您可以在此处了解更多信息: https://github.com/thibautd/JSerial !
目前仅支持 Windows,但我计划支持 Linux。 如果需要,您可以使用最新的 Visual Studio 轻松修改本机部分。
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.