java - CommPortIdentifier.getPortIdentifier() 导致程序崩溃

标签 java io

我有一些可以在 Windows 7 中运行的代码,但是当我在 Windows 10 计算机上尝试相同的代码时,程序会关闭。代码如下:

try {
    CommPortIdentifier portId = CommPortIdentifier.getPortIdentifier((String)openParameters[0]);
    this._serCommPort = (SerialPort) portId.open("PTxCore", 1000);
    this._serCommPort.setSerialPortParams((int)openParameters[1], (int)openParameters[2], SerialPort.STOPBITS_1, (int)openParameters[3]);
    this._serCommPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
    this._serCommPort.addEventListener(this);
    this._serCommPort.notifyOnDataAvailable(true);
    this._commsOutStream = this._serCommPort.getOutputStream();
    this._commsInStream = this._serCommPort.getInputStream();

    this.clearBuffer();

    this.onTraceEvent(TraceEventArgs.Mode.Hidden, "{Open}");
}
catch (UnsupportedCommOperationException | TooManyListenersException | IOException | PortInUseException | NoSuchPortException ex) {
    throw new PTxCoreException(ex.getMessage(), ex.getClass().getName());
}
}

没有捕获任何异常,它只是关闭。我尝试了不同版本的 Eclipse(32/64 位),并在网上到处查找,但找不到解决方案。知道为什么会发生这种情况吗? Serialio.jar(我认为它可以处理这个问题?)显然与 Windows 10 兼容。

当它关闭时,我收到此错误:

...javaw.exe

Eclipse 底部还有这些东西:

javax.comm.SerialPort implementation: version 3.8
Copyright (c) 1998-2009 Serialio.com, All Rights Reserved.
Serialio Library: version 10.1.2: build 9221
Copyright (c) 1996-2012 Serialio.com, All Rights Reserved.
os.name="Windows 10"  os.arch="x86"
osName=Windows 10 osArch=x86
Platform not supported, check VM properties os.name & os.arch

最佳答案

虽然回复有点晚,但可能对某人有帮助。我遇到了同样的错误。这是因为我使用的是旧版本的 Serialio.jar。将其升级到最新版本(我认为版本:9233?)后,它开始在 Windows 10 上正常运行。

关于java - CommPortIdentifier.getPortIdentifier() 导致程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37197840/

相关文章:

java - 使用 setIcon 重叠图像

python - 如何使用 PyCall 在 Julia 中使用内置的 Python read() 函数?

java - 从不断更新的文件中读取完整的行

C# 找不到网络路径

vb.net 从 "GetFiles"中排除扩展名

java - Raspberry Pi 和 javaFX 命令错误

java - 谷歌分析 : Get access token from refresh token

java - Java中如何使用FileInputStream

java - @EnableTransactionManagement 的范围是什么?

java - 骰子统计程序