7

I just run some codes to get a list of available ports n my cmputer and it returned me false when I have 3 com ports that are free. How do I solve this prob?

My codes:

public static void main(String[] args) {
        //SerialParameters params=new SerialParameters();
       // System.out.println(CommPortIdentifier.PORT_SERIAL );
        Enumeration portList = CommPortIdentifier.getPortIdentifiers();
        System.out.println(portList.hasMoreElements());
        while(portList.hasMoreElements()){
            System.out.println("Has more elements");
             CommPortIdentifier portId = (CommPortIdentifier) portList.nextElement();
               if (portId.getPortType() == CommPortIdentifier.PORT_PARALLEL) {
                    System.out.println(portId.getName());
               }
               else{
                     System.out.println(portId.getName());
               }

        }
}

Output : false

Heisenbug
  • 38,762
  • 28
  • 132
  • 190
Manish Basdeo
  • 6,139
  • 22
  • 68
  • 102

3 Answers3

4

It appears your setup of the javax.comm API may not be correct. Make sure you have done the following:

  1. Placed the comm.jar file in the jre/lib/ext directory.
  2. Placed the javax.comm.properties file in the jre/lib directory.
  3. Placed the win32com.dll in the jre/bin directory.

Each of the above components "should" be available here.

0

I'm using ubuntu and my computer does not have any serial/pararel port.

You need to simulate this ports in this case.

My answer:

serial port identification with java on ubuntu

Community
  • 1
  • 1
Marcelo Amorim
  • 1,662
  • 23
  • 23
-1

I have an additional answer, if you happen to do what I naively did.

I just forgot to add my user to the dialout group, and the result was to find no serial ports, while my /dev/ttyUSB0 was forwarded correctly to my VirtualBox instance of a Lubuntu machine.

LuC
  • 347
  • 2
  • 10