跳转到主要内容

raydriver.core.discovery.ports

Constants​

list_serial_ports​

Any

SerialPortInfo​

A serial port path together with optional metadata used to identify the underlying USB device.

description​

description: Optional[str]

device​

device: str

manufacturer​

manufacturer: Optional[str]

pid​

pid: Optional[int]

vid​

vid: Optional[int]

Functions​

glob_ports()​

glob_ports(dir: str, prefix: str) -> list[str]

Glob-style prefix listing of one directory; the enumeration backend used by the sandbox-safe listing. Exposed as a module attribute so tests can replace it.

ParameterTypeDescription
dirstr
prefixstr
Returnslist[str]

is_usb_serial_port()​

is_usb_serial_port(port: str) -> bool

Heuristically determines if a port path refers to a USB serial device. On non-POSIX systems (e.g. Windows), every port is treated as potentially USB.

ParameterTypeDescription
portstr
Returnsbool

list_port_info()​

list_port_info() -> list[SerialPortInfo]

Lists available serial ports together with a human-readable description when the platform provides one. USB adapters are listed first.

ParameterTypeDescription
Returnslist[SerialPortInfo]

list_ports()​

list_ports() -> list[str]

Lists available serial ports, USB adapters first.

ParameterTypeDescription
Returnslist[str]

list_usb_ports()​

list_usb_ports() -> list[str]

Like list_ports, but only returns USB serial ports.

ParameterTypeDescription
Returnslist[str]

natural_key()​

natural_key(s: str) -> list

Splits a string into lowercase words and numbers so ttyUSB2 sorts before ttyUSB10.

ParameterTypeDescription
sstr
Returnslist

safe_list_ports_linux()​

safe_list_ports_linux() -> list[str]

A non-crashing port listing for sandboxed Linux envs.

Direct enumeration of /dev/ttyS* is forbidden by the snap sandbox and crashes pyserial-style scanners; only the common USB-to-serial patterns permitted by the serial-port interface are globbed.

ParameterTypeDescription
Returnslist[str]

sort_ports()​

sort_ports(ports: Sequence[str]) -> list[str]

Sorts ports so USB serial adapters come first, followed by all other ports. Each group is ordered naturally, e.g. ttyUSB2 before ttyUSB10.

ParameterTypeDescription
portsSequence[str]
Returnslist[str]