bpod_core.com.ChunkedSerialReader

class bpod_core.com.ChunkedSerialReader

Bases: Protocol

A protocol for reading chunked data from a serial port.

This class provides methods to buffer incoming data and retrieve it in chunks.

__init__(chunk_size, callback, buffer=None) None

Initialize the protocol.

Parameters:
  • chunk_size (int) – The fixed size of chunks to emit to the callback function when enough data has accumulated in the buffer.

  • callback (Callable) – A function to call with each chunk of data.

  • buffer (bytearray, optional) – Pre-allocated buffer to use for accumulation. If None, a new bytearray is created.

Return type:

None

connection_lost(exc) None

Called when the serial port is closed or the reader loop terminated otherwise.

Parameters:

exc (BaseException, optional) – The exception that caused the connection to be closed, if any.

Return type:

None

connection_made(transport) None

Called when a connection is made.

Parameters:

transport (ReaderThread) – The reader thread that created this protocol instance.

Return type:

None

data_received(data) None

Called with snippets received from the serial port.

Parameters:

data (bytes) – The binary data received from the serial port.

Return type:

None