Skip to content

serial_device

frog.hardware.serial_device ¤

Provides a base class for serial devices.

Attributes¤

Classes¤

SerialDevice(port, baudrate) ¤

Bases: AbstractDevice

A base class for 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/name of serial port

required
baudrate int

Baud rate of port

required
Source code in src/frog/hardware/serial_device.py
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
def __init__(self, port: str, baudrate: int) -> None:
    """Create a new serial device.

    Args:
        port: Description/name of serial port
        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 src/frog/hardware/serial_device.py
157
158
159
def close(self) -> None:
    """Close the connection to the device."""
    self.serial.close()