panoptes.utils.serial package


panoptes.utils.serial.device module

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

Bases: object


Connect to device and add default reader.


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 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


baudrate: int = 9600
bytesize: int = 8
dsrdtr: bool = False
parity: str = 'N'
rtscts: bool = False
stopbits: int = 1
timeout: float = 1.0

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)  

>>> # Raises error when not found.
>>> find_serial_port(0x1234, 0x4321)
Traceback (most recent call last):
panoptes.utils.error.NotFound: NotFound: No serial ports...
  • 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.


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

Return type:

str or list


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             
[< 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:

Module contents