CommPortIdentifier.getPortIdentifiers is empty

I am creating a simple application that communicates via a serial port using the Java Communication API javax.comm.

Here is some code in my main java method that I wrote:

CommPortIdentifier cpi = null;
        Enumeration e = CommPortIdentifier.getPortIdentifiers();
        while (e.hasMoreElements()) {
            try {
                cpi = (CommPortIdentifier) e.nextElement();
            } catch (NoSuchElementException n) {

            }
            System.out.println(cpi.getName());
        }

Listing e is always empty, even if I am connected to the COM port when doing this.

also by running this code:

portRead = CommPortIdentifier.getPortIdentifier("COM8");

trigger a throw NoSuchPortException

I think I did the part of the installation correctly and placed the properties file, the win32com.dll file in the right places.

Do you know what the problem may be?

thank

+5
source share
4 answers

Make sure win32com.dll (shipped with javax.com) is located in the jre \ bin directory. Make sure javax.comm.properties (shipped with javax.com) is located in the jdk \ lib directory.

+3

, javax.comm.zip jre

win32com.dll - jre/bin

comm.jar - jre/lib/ext

java.comm.properties - jre/lib ( )

+5

Find the port where your device is running (try a shell shell or a hyperlink to find all COM ports, try the link )

-1
source

All Articles