Fazecast / jSerialComm

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

This port appears to have been shutdown or disconnected. #397

Closed piotrg44 closed 2 years ago

piotrg44 commented 2 years ago

Hi,

        comPort.openPort();
        comPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_SEMI_BLOCKING, 0, 0);
        InputStream in = comPort.getInputStream();
        try {
            System.out.println(in.read());
        }
        catch(IOException e) {
            e.printStackTrace();
        }

This block of code gives me error:

com.fazecast.jSerialComm.SerialPortIOException: This port appears to have been shutdown or disconnected. at com.fazecast.jSerialComm.SerialPort$SerialPortInputStream.read(SerialPort.java:1809) at UsbConnection.Main.main(Main.java:27)

comPort.getLastErrorCode() return -> 11 comPort.getLastErrorLocation() return -> 394

When I check value comPort.isOpen() after comPort.openPort() it always returns false.

crw-rw---- 1 root dialout 166, /dev/ttyACM0 I'm in dialot group in linux

Peter

hedgecrw commented 2 years ago

That line and error code indicate that some other process on your computer already has an exclusive lock on the serial port, so jSerialComm cannot safely open the port. You can force it to skip this check by calling comPort.disableExclusiveLock() before calling comPort.openPort(), but this is just a band-aid, and you may still run into errors unless you find out what other process currently has your port locked.

piotrg44 commented 2 years ago

Thanks, lsof list me a few process locking my serial port. It happen because i terminate application in Eclipse and the process which lock my serial port was not terminated. When i manually kill all of process the exception is gone.