Skip to content

serial_device

frog.hardware.serial_device ¤

Provides a base class for USB serial devices.

Attributes¤

Classes¤

SerialDevice(port, baudrate) ¤

Bases: AbstractDevice

A base class for USB serial devices.

Note that it is not sufficient for a device type class to inherit from this class alone: it must also inherit from a device base class. When doing so, this class must be listed before any other parent classes, otherwise the ABC won't be able to find this class's implementation of close() and will complain about missing functions.

Create a new serial device.

Parameters:

Name Type Description Default
port str

Description of USB port (vendor ID + product ID)

required
baudrate int

Baud rate of port

required
Source code in frog/hardware/serial_device.py
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
def __init__(self, port: str, baudrate: int) -> None:
    """Create a new serial device.

    Args:
        port: Description of USB port (vendor ID + product ID)
        baudrate: Baud rate of port
    """
    # If port is unknown, it may be because the user connected the device after the
    # list of serial ports was retrieved, so we refresh the list to check if it is
    # now available. Similarly, the COM port may have changed due to the user
    # disconnecting and reconnecting the device, in which case we also need to
    # refresh the list.
    try:
        self.serial = _create_serial(port, baudrate, refresh=False)
    except SerialException:
        self.serial = _create_serial(port, baudrate, refresh=True)
Attributes¤
serial = _create_serial(port, baudrate, refresh=False) instance-attribute ¤

Underlying serial device.

Functions¤
close() ¤

Close the connection to the device.

Source code in frog/hardware/serial_device.py
149
150
151
def close(self) -> None:
    """Close the connection to the device."""
    self.serial.close()