我的RXTX库有问题。我试图一次向我的项目添加对多个串口读写的支持,并在运行时开始接收以下消息。
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000001800071cd, pid=9032, tid=5016
#
# JRE version: Java(TM) SE Runtime Environment (7.0_51-b13) (build 1.7.0_51-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.51-b03 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C [rxtxSerial.dll+0x71cd]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Users\Jack\workspace\TestProject\hs_err_pid9032.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#我已经能够隔离产生此崩溃的代码,并希望有人能够解释为什么会发生这种情况,并且/或可能验证这确实是rxtx的预期行为(而不是我的设置的某些错误配置的结果)。RXTX每次都抱怨我的本地库和jar之间的不匹配。本机-lib2.2pre2和jar版本2.1-7,但到目前为止,我忽略了这一点,没有明显的不良影响)
产生错误的最简单代码:
public static void main(String[] args) throws Exception {
CommPortIdentifier com13PI = CommPortIdentifier
.getPortIdentifier("COM13");
CommPortIdentifier com1PI = CommPortIdentifier
.getPortIdentifier("COM1");
SerialPort com13 = (SerialPort) com13PI.open(main.class.getName(), 400);
SerialPort com1 = (SerialPort) com1PI.open(main.class.getName(), 400);
com13.close();
//com1.close();
com13PI = CommPortIdentifier.getPortIdentifier("COM13");
com13 = (SerialPort) com13PI.open(main.class.getName(), 400);
}关键的一行是‘com1.lose()’,它目前被注释掉了。未注释时,此代码工作正常。在它当前的形式中,它会产生上述异常。
RXTX的文档非常缺乏,我无法判断这是否是预期的行为。然而,打开和关闭一个串行端口,而另一个串口保持打开的功能,似乎是在使用rxtx库时经常出现的东西,因此如果这是RXTX中的未修复错误,则似乎有点令人震惊。如果安装了rxtx的人能够测试这段代码并报告结果,或者提供解释,我将不胜感激。
发布于 2014-06-20 01:38:07
我没有带我的串行调制解调器,但我记得有类似的问题。
首先,检查com1.lose()周围是否有异常。如果您得到一个IOException,那么这是因为流仍然有内容,并且它被卡住了。如果该流上有一个消费者,但是没有任何处理,则会发生这种情况。想想看,在Linux find . | yourscript中,您的脚本并没有消耗find .生成的管道。
您应该能够打开和关闭端口,但IMHO RxTx实际上是变化无常的,当周围的情况没有太大变化时,它工作得很好。
https://stackoverflow.com/questions/24318676
复制相似问题