bpod_core.serial.ExtendedSerial
- class bpod_core.serial.ExtendedSerial
Enhances
serial.Serial
with additional functionality.- query(query, size=1)
Query data from the serial port.
- query_struct(query, format_string)
Query structured data from the serial port.
This method queries a specified number of bytes from the serial port and unpacks it into a tuple according to the provided format string.
- Parameters:
query (
any
) – Query to be sent to the serial port.format_string (
str
) – A format string that specifies the layout of the data to be read. It should be compatible with the struct module’s format specifications. See https://docs.python.org/3/library/struct.html#format-characters
- Returns:
A tuple containing the unpacked data read from the serial port. The structure of the tuple corresponds to the format specified in format_string.
- Return type:
tuple[Any
,]
- read_struct(format_string)
Read structured data from the serial port.
This method reads a specified number of bytes from the serial port and unpacks it into a tuple according to the provided format string.
- Parameters:
format_string (
str
) – A format string that specifies the layout of the data to be read. It should be compatible with the struct module’s format specifications. See https://docs.python.org/3/library/struct.html#format-characters- Returns:
A tuple containing the unpacked data read from the serial port. The structure of the tuple corresponds to the format specified in format_string.
- Return type:
tuple[Any
,]
- verify(query, expected_response)
Verify the response of the serial port.
This method sends a query to the serial port and checks if the response matches the expected response.
- write(data)
Write data to the serial port.
This method extends
serial.Serial.write()
with support for NumPy types, unsigned 8-bit integers, strings (interpreted as utf-8) and iterables.
- write_struct(data, format_string)
Write structured data to the serial port.
This method packs the provided data into a binary format according to the specified format string and writes it to the serial port.
- Parameters:
data (
Sequence[Any]
) – A sequence of data to be packed and written, corresponding to the format specifiers in format_string.format_string (
str
) – A format string that specifies the layout of the data. It should be compatible with the struct module’s format specifications. See https://docs.python.org/3/library/struct.html#format-characters
- Returns:
The number of bytes written to the serial port, or None if the write operation fails.
- Return type:
int | None