Fazecast / jSerialComm

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

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

Closed jmspaggi closed 8 months ago

jmspaggi commented 8 months ago

Hi,

I seem to face a situation that others faced in the past and which should be fixed, but running the last version of jSerialComm I'm still facing it.

I have this very simple code:

    SerialPort comPort = SerialPort.getCommPorts()[0];
    comPort.openPort();
    comPort.setComPortTimeouts(SerialPort.TIMEOUT_WRITE_BLOCKING, 0, 0);
    OutputStream os = comPort.getOutputStream();
    String command = "#3P1500S75" + (char)13;
    try {
        os.write(command.getBytes());
    } catch (IOException e) {
        e.printStackTrace();
    }
    comPort.closePort();

But I'm getting the following exception: com.fazecast.jSerialComm.SerialPortIOException: This port appears to have been shutdown or disconnected.

If I replace the os.write by "comPort.writeBytes(command.getBytes(), command.length());" I don't get any exception, but it seems that nothing is sent. I tested with picocom from the command line to make sure the receiver is well receiving and it works. Any guidance?

Thanks.

jmspaggi commented 8 months ago

Responding to my self, in case someone is ready later.

This was due to permissions! I just updated it and now it works: sudo chmod a+rw /dev/ttyUSB0