我正在构建一个简单的应用程序,它使用 Java 通信 API javax.comm 通过串行端口进行通信。
这是我在 java main 方法中编写的一些代码:
CommPortIdentifier cpi = null;
Enumeration e = CommPortIdentifier.getPortIdentifiers();
while (e.hasMoreElements()) {
try {
cpi = (CommPortIdentifier) e.nextElement();
} catch (NoSuchElementException n) {
}
System.out.println(cpi.getName());
}
枚举 e 始终为空,即使我在运行时连接到 COM 4 端口也是如此。
另外,运行这段代码:
portRead = CommPortIdentifier.getPortIdentifier("COM8");
导致抛出 NoSuchPortException
我想我已经正确完成安装部分并将属性文件 win32com.dll 文件放在正确的位置。
你知道问题出在哪里吗?
谢谢
最佳答案
请始终记住,您需要将所有解压缩的文件从 javax.comm.zip 添加到 jre
win32com.dll - jre/bin
comm.jar - jre/lib/ext
java.comm.properties - jre/lib(添加后我发现异常问题已解决)
关于java - CommPortIdentifier.getPortIdentifiers 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15955530/