Fazecast / jSerialComm

Platform-independent serial port access for Java
GNU Lesser General Public License v3.0
1.35k stars 287 forks source link

How can I see if a COM port is available? #570

Closed sblantipodi closed 2 months ago

sblantipodi commented 2 months ago

Hi, thanks for this wonderful lib, Java really needed something good like this.

Thanks for the effort you put into it to make it real.

Is it possible to see if a COM port is available?

SerialPort[] ports = SerialPort.getCommPorts();
        for (SerialPort port : ports) {
            if (port.isOpen()) {
                // not available
            } else {
               // available
            }
        }

this code says that the com port is always available, even if all the ports are locked/opened by other programs.

NorbertSandor commented 2 months ago

Try to open the port, it will fail if it has been opened by another process. (isOpen() only indicates whether the port has been opened by using the given SerialPort instance.)

sblantipodi commented 2 months ago

ok thanks it worked 👍 congrats for the wonderful lib!