Skip to content

Unable to properly reopen serial device after it disappears #51

@jasongaunt

Description

@jasongaunt

Hi all, I'm using this library on Linux to configure and maintain connectivity of a USB LTE modem. One of the steps results in the modem "disappearing" as it restarts. My modems TTY device (/dev/ttyACM0 in my case but this would also apply to /dev/ttyUSBx and similar) disappears and reappears about 5 seconds later.

I put in code to handle that by checking for the existence of /dev/ttyACM0 before reading / writing to it and to execute serial.Close() and then (after a small delay) serial.Open() again. There are no errors re-opening the device, but the moment I try and call serial.Read() or serial.Write() the Go program errors out with the following;

Error reading from serial port: read /dev/ttyACM0: file already closed
or
Error writing to serial port: write /dev/ttyACM0: file already closed

How can I handle this without restarting the Go program? To me it seems like the Close() event isn't fully doing its task or some state in the serial library is persisting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions