panoptes.utils.serial package

Submodules

panoptes.utils.serial.device module

class panoptes.utils.serial.device.SerialDevice(port: str | None = None, name: str | None = None, reader_callback: Callable | None = None, serial_settings: SerialDeviceDefaults | dict | None = None, reader_queue_size: int = 50)[source]

Bases: object

connect()[source]

Connect to device and add default reader.

disconnect()[source]

Disconnect from the device and reset the reader thread.

property is_connected

True if serial port is open, False otherwise.

property port

Name of the port.

write(line)[source]

Write to the serial device.

Note that this expects unicode and will handle adding a newline at the end.

class panoptes.utils.serial.device.SerialDeviceDefaults(baudrate: int = 9600, timeout: float = 1.0, write_timeout: float = 1.0, bytesize: int = 8, parity: str = 'N', stopbits: int = 1, xonxoff: bool = False, rtscts: bool = False, dsrdtr: bool = False)[source]

Bases: object

Dataclass for the serial port defaults.

This can be instantiated with changed values and then passed to the serial device via the apply_settings method.

Values are:

write_timeout, inter_byte_timeout, dsrdtr, baudrate, timeout, parity, bytesize, rtscts, stopbits, xonxoff

See https://pyserial.readthedocs.io/en/latest/pyserial_api.html#serial.Serial.get_settings

baudrate: int = 9600
bytesize: int = 8
dsrdtr: bool = False
parity: str = 'N'
rtscts: bool = False
stopbits: int = 1
timeout: float = 1.0
to_dict()[source]

Return fields as dict.

write_timeout: float = 1.0
xonxoff: bool = False
panoptes.utils.serial.device.find_serial_port(vendor_id, product_id, return_all=False)[source]

Finds the serial port that matches the given vendor and product id.

>>> from panoptes.utils.serial.device import find_serial_port
>>> vendor_id = 0x2a03  # arduino
>>> product_id = 0x0043 # Uno Rev 3
>>> find_serial_port(vendor_id, product_id)  
'/dev/ttyACM0'

>>> # Raises error when not found.
>>> find_serial_port(0x1234, 0x4321)
Traceback (most recent call last):
  ...
panoptes.utils.error.NotFound: NotFound: No serial ports...
Parameters:
  • vendor_id (int) – The vendor id, can be hex or int.

  • product_id (int) – The product id, can be hex or int.

  • return_all (bool) – If more than one serial port matches, return all devices, default False.

Returns:

Either the path to the detected port or a list of all comports that match.

Return type:

str or list

panoptes.utils.serial.device.get_serial_port_info()[source]

Returns the serial ports defined on the system sorted by device name.

>>> from panoptes.utils.serial.device import get_serial_port_info
>>> devices = get_serial_port_info()
>>> devices             
[<serial.tools.list_ports_linux.SysFS object at 0x7f6c9cbd9460>]
>>> devices[0].hwid     
'USB VID:PID=2886:802D SER=3C788B875337433838202020FF122204 LOCATION=3-5:1.0'
Returns: a list of PySerial’s ListPortInfo objects. See:

https://github.com/pyserial/pyserial/blob/master/serial/tools/list_ports_common.py

Module contents