我正在开发一个使用 Java 与串行端口通信的项目。我是否需要将设备连接到串口来测试以下代码?
Enumeration ports = CommPortIdentifier.getPortIdentifiers();
while (ports.hasMoreElements()) {
CommPortIdentifier port = (CommPortIdentifier) ports.nextElement();
String type;
switch (port.getPortType()) {
case CommPortIdentifier.PORT_PARALLEL:
type = "Parallel";
break;
case CommPortIdentifier.PORT_SERIAL:
type = "Serial";
break;
default: /// Shouldn't happen
type = "Unknown";
break;
}
System.out.println(port.getName() + ": " + type);
}
使此代码正常工作的任何解决方案。目前我收到如下错误。(没有将任何设备连接到串口。
Exception in thread "main" java.lang.UnsatisfiedLinkError: com.sun.comm.SunrayInfo.isSessionActive()Z
at com.sun.comm.SunrayInfo.isSessionActive(Native Method)
at com.sun.comm.Portmapping.registerCommPorts(Portmapping.java:155)
at com.sun.comm.Portmapping.refreshPortDatabase(Portmapping.java:100)
at javax.comm.CommPortIdentifier.<clinit>(CommPortIdentifier.java:138)
at PortTest.main(PortTest.java:9)
Java Result: 1
我已经用 jre 配置了 comm。我已经按照这个博客去做了。