bpod_core.com.ExtendedSerial
- class bpod_core.com.ExtendedSerial
Bases:
SerialEnhances
serial.Serialwith additional functionality.- query_struct(query, format_string) tuple[Any, ...]
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 (
Buffer) – 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) tuple[Any, ...]
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=b'', expected_response=b'\\x01') bool
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.
- Parameters:
query (
Buffer, optional) – The query to be sent to the serial port. Defaults to an empty byte string.expected_response (
bytes, optional) – The expected response from the serial port. Default: b’x01’.
- Returns:
True if the response matches the expected response, False otherwise.
- Return type:
- write_struct(format_string, *data) int | None
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:
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*data (
Any) – Variable-length arguments representing the data to be packed and written, corresponding to the format specifiers in format_string.
- Returns:
The number of bytes written to the serial port, or None if the write operation fails.
- Return type:
int | None- Raises:
struct.error – Error occurred during packing of the data into binary format.
serial.SerialTimeoutException – In case a write timeout is configured for the port and the time is exceeded.