CommPortIdentifier.getPortIdentifier(端口名称)抛出异常

CommPortIdentifier.getPortIdentifier(portname) throughing exception

在代码中:CommPortIdentifier.getPortIdentifier(端口名称)无法识别 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;
    }}

我已经尝试了 link how-to-install-java-communications 中的解决方案 但失败了,请帮助我。

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