Der_ Floh
Der_ Floh

Reputation: 33

How do I find the right SerialPort name?

I want to read out some information from a Arduino over the serial port.

I use the jSerialComm library.

Here's my code:

SerialPort serialPort = SerialPort.getCommPort("COM3");
serialPort.setComPortParameters(9600, 8, 1, 0);

if(serialPort.isOpen())
{
  System.out.println("SerialPort is open");
}
else
{
  System.out.println("SerialPort is not open");
}

Sadly, the program says that the port is closed, but I know it's not. I guess that I named it wrong here: SerialPort.getCommPort("COM3"); So how do I have to name it so it will work?

Upvotes: 1

Views: 1301

Answers (1)

ocrdu
ocrdu

Reputation: 2183

Not sure if any of this works (can't test atm), but I hope it does:

  • You could maybe look up the name in Device Manager -> Ports;

  • You can try running this and see what it says:

SerialPort[] list= SerialPort.getCommPorts();
if (list.length == 0) {
  System.out.println("No ports found");
} else {
  for (int i = 0; i < list.length; i++) {
    System.out.println("Port " + i + ": " + list[i].getDescriptivePortName());
  }
}
  • Or you could just try this and see what happens:
SerialPort serialPort = SerialPort.getCommPorts()[3];

Also, have a look at your baudrates, try with the Serial Monitor closed, and try an other USB cable.

Upvotes: 1

Related Questions