简体   繁体   中英

CommPortIdentifier.getPortIdentifier(portname) throughing exception

In the code: CommPortIdentifier.getPortIdentifier(portname) is not able to indentify the 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;
    }}

I have tried the solution in the link how-to-install-java-communications but failed, please help me regarding.

The solution provided in the https://edn.embarcadero.com/article/31915 works. In my case, I was using both 32 bit JRE and 64 bit JRE on my PC. I placed the required files according to my java home and used different JRE.

To download comm.jar, win32com.dll and property file I have used http://kishor15389.blogspot.de/2011/05/how-to-install-java-communications.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM