RXTX 中是否需要持续轮询?
在试图找出这个问题时(感谢任何帮助),我在监控时运行了 RXTX使用 PortMon 进行活动,并注意到 RXTX 不断检查数据是否可用,即使 Java 客户端仅通过 SerialPortEventListener 从 gnu.io.SerialPort 对象读取。
这是为什么呢?这是 RXTX 人员的一个糟糕的实现选择,还是 Sun 的一个糟糕的 API 选择(因为 RXTX 遵循 javax.comm API),或者是本地代码支持的运行 Java 的限制?
另一方面,超级终端不进行轮询(并且工作没有问题)。它是否可以访问一些隐藏的 Windows 系统调用来执行此操作?
While trying to figure out this problem (any help there is appreciated), I ran RXTX while monitoring its activity using PortMon and noticed that RXTX constantly checks if data is available, even when the Java client reads from the gnu.io.SerialPort object only through a SerialPortEventListener.
Why is this? Is it a poor implementation choice by the RXTX folks, a poor API choice by Sun (since RXTX follows the javax.comm API), or a limitation of running Java supported by native code?
Hyperterminal, on the other hand, does no polling (and works without a problem). Does it have access to some hidden Windows system calls that let it do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,这不是由于 javax.xomm API 造成的。顺便说一句,Rxtx 可以通过该 API 使用,也可以不使用。
Rxtx 内部结构有点不同/奇怪,并且有一些错误。
简短版本,这就是它应该如何工作:您有两个参数可以使用:超时和阈值。根据源代码,将超时设置为 0(无)并将阈值设置为 1(在返回之前需要至少 1 个字节)应该会为我们提供正常的(由 InputStream 定义的)阻塞读取。
问题是,即使这样设置,当前稳定版本(2.1.7r2)中也存在错误。阈值参数始终设置为 0!从源代码:
/* TESTING ttyset.c_cc[ VMIN ] = Threshold; */
ttyset.c_cc[VMIN] = 0;
令人困惑的部分是,2004 年也是这种情况,并在邮件列表上报告并修复了,但它要么没有真正修复,要么又回来了(回归)。实际上有一个新的错误报告,由于某种原因我一开始找不到。我最终发现它会抛出预发布包源代码,并发现一个未发布的更改日志(该网页在最后一个稳定版本之后不显示更改日志,尽管它在 CVS 中可用)。
解决方案
(2.2-系列)或从 CVS 编译它。
按照以下方式制定一个丑陋的解决方法:
然后您执行:
read(in)
而不是in.read()
。实际上,我两年前写了关于此的博客文章,所以我不会忘记。
No it's not due to the javax.xomm API. Rxtx can be used through that API or not by the way.
Rxtx internals are a bit different/weird though and has some bugs.
Short version, this is how it is supposed to work: You have two parameters to play with: timeout and threshold. According to the source code setting the timeout to 0 (none) and threshold to 1 (requiring at least 1 byte before returning) should give us normal, by InputStream defined, blocking reads.
The problem is that even when setting it up like this there is a bug in the current stable release (2.1.7r2). The threshold parameter is always set to 0! From the source code:
/* TESTING ttyset.c_cc[ VMIN ] = threshold; */
ttyset.c_cc[ VMIN ] = 0;
The confusing part is that this was also the case in 2004 and reported on the mailing list and fixed, but it was either not really fixed or has come back again (a regression). There is actually a new bug report that for some reason I couldn’t find at first. I eventually found it going throw the pre-release package source code and found an otherwise not published change log (the web page doesn’t show change logs after the last stable version, its available in CVS though).
Solution
(2.2-series) or compile it from CVS.
Make an ugly workaround along the lines of:
Then you do:
read(in)
instead ofin.read()
.I actually wrote a blog entry about this 2 years ago so I wouldn't forget.