plesty.lib.traffic.serial_ports

Explain why a serial port refused to open.

pyserial reports every open failure as SerialException, and the two that matter most look alike in a log line: a port that does not exist and a port that exists but is held. The second one costs sessions — the user re-checks drivers and port names while Thorlabs Kinesis, a serial terminal, or a stray interpreter still owns the device.

Attributes

_WINDOWS_OSERROR

_HELD_HINT

_DIALOUT_HINT

Functions

_open_errno(→ int | None)

Return the OS error number behind a serial open failure, if any.

describe_port(→ str)

Return device: description, hwid for port, or "" when unlisted.

explain_serial_open_error(→ str | None)

Return one sentence of guidance for a serial open failure, or None.

Module Contents

plesty.lib.traffic.serial_ports._WINDOWS_OSERROR
plesty.lib.traffic.serial_ports._HELD_HINT = 'The port exists but is open in another process. Close Thorlabs Kinesis/APT (a loaded stage...
plesty.lib.traffic.serial_ports._DIALOUT_HINT = 'Not permitted to open the port. Add the user to the serial group (`sudo usermod -aG dialout...
plesty.lib.traffic.serial_ports._open_errno(exc: BaseException) int | None

Return the OS error number behind a serial open failure, if any.

Parameters:

exc (BaseException)

Return type:

int | None

plesty.lib.traffic.serial_ports.describe_port(port: str) str

Return device: description, hwid for port, or "" when unlisted.

Parameters:

port (str) – A port name as passed to serial.Serial.

Return type:

str

plesty.lib.traffic.serial_ports.explain_serial_open_error(exc: BaseException, port: str, platform: str | None = None) str | None

Return one sentence of guidance for a serial open failure, or None.

Only EACCES and EBUSY are explained — they are the two a user cannot tell apart from a wrong port name, and the two whose remedy is not on the device side. Everything else (ENOENT, timeouts) is left to speak for itself.

Parameters:
  • exc (BaseException) – The exception serial.Serial raised.

  • port (str) – The port that was being opened, for the list_ports line.

  • platform (str | None) – sys.platform override for tests; None reads it.

Return type:

str | None