CommPortIdentifier.getPortIdentifier(portname) 通过异常



在代码中:CommPortIdentifier.getPortIdentifier(portname(无法识别ComPort。

{CommPortIdentifier cpi = null;
try {
cpi = CommPortIdentifier.getPortIdentifier(portname);
if (cpi.isCurrentlyOwned()) {
System.out.println("Error: Port is currently in use");
}
com = (SerialPort) cpi.open("COM", 10);
com.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
} catch (Exception e1) {
e1.printStackTrace();
return false;
}}

我已经尝试了链接中的解决方案 如何安装-java-通信 但失败了,请帮助我。

https://edn.embarcadero.com/article/31915 中提供的解决方案有效。就我而言,我在PC上同时使用了32位JRE和64位JRE。我根据我的 java 主页放置了所需的文件并使用了不同的 JRE。

要下载我使用的comm.jar,win32com.dll和属性文件 http://kishor15389.blogspot.de/2011/05/how-to-install-java-communications.html

最新更新