Why am I getting a Java NoSuchPortException when the port exists?(当端口存在时,为什么我会收到 Java NoSuchPortException?)
问题描述
得到以下生产代码,我正在将其用于新驱动程序.portName 是 COM4 并且这个端口存在于 PC 上(我可以通过超级终端连接到它),那么为什么 Javacomm 会抛出 NoSuchPortException 呢?COM4 在设备管理器中显示良好.太
Got the following production code below, I'm using it for a new driver. portName is COM4 and this port exists on the PC (and I can connect to it with hyperterminal), so why does Javacomm throw a NoSuchPortException? COM4 shows up fine in device mgr. too
final String portName = getSerialPort();
try {
final CommPortIdentifier id = CommPortIdentifier.getPortIdentifier(portName);
port = (SerialPort) id.open(getName(), 1000);
} catch (NoSuchPortException nspe) {
report(SeverityCode.LEVEL2, getName(), "PIN Pad is not connected to " + portName + " port, or the port does not exist.");
return;
} catch (PortInUseException piue) {
report(SeverityCode.LEVEL2, getName(), portName + " port is already in-use by some other device. Reason: " + piue.getMessage());
return;
}
推荐答案
尝试使用 CommPortIdentifier.getPortIdentifiers()
枚举系统上可用的端口列表并打印列出的内容.您确定将 jarfiles 和 dll 安装在正确的文件夹中吗?如果是,则尝试使用 CommPortIdentifier.addPortName(java.lang.String portName, int portType, CommDriver driver)
添加 COM4.您可以将驱动程序参数设置为 null 以使用默认驱动程序.
Try enumerating the list of ports that are available on your system using the CommPortIdentifier.getPortIdentifiers()
and print what's listed. Are you sure that you installed the jarfiles and dll in the correct folders? If yes, then try adding COM4 using CommPortIdentifier.addPortName(java.lang.String portName, int portType, CommDriver driver)
.You can set the driver parameter to null to use the default driver.
这篇关于当端口存在时,为什么我会收到 Java NoSuchPortException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:当端口存在时,为什么我会收到 Java NoSuchPortException?
基础教程推荐
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 降序排序:Java Map 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01