0
在代碼中:CommPortIdentifier.getPortIdentifier(portname)無法識別ComPort。CommPortIdentifier.getPortIdentifier(portname)通過異常
{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;
}}
我試圖在鏈接how-to-install-java-communications 的解決方案,但失敗了,請幫我有關。