Brian to Brian communication

class brian.sensors.BrianBrianComm.BrianBrianComm(port: SensorPort, is_master: bool)

Bases: Sensor

Class exposing the communication between two Brians connected via a sensor port.

Sensor (other Brian) is automatically registered in the constructor of the base class and un-registered in its destructor.

There can be at most one instance at any given time, of any sensor class per port in the entire program.

__init__(port: SensorPort, is_master: bool) None

Initialize a new Brian-Brian communication handler at the given port. The communication can be initialized in either of two modes - master and slave. One of the ends must be master, the other must be slave.

Parameters:
  • port – Sensor port to which the sensor is attached.

  • is_master – true if this should be used in master mode, false for slave mode

available() int
Returns:

bytes available to be read

read(size: int | None = None) bytes

reads data incoming from the other Brian.

Parameters:

size – size limit, how many bytes to copy. If not provided, all available data will be read.

Returns:

read bytes

Raises:

OSError – If an error occurs during the write operation.

Error Codes: MP_EIO: BrianBrianComm is not ready or is disconnected.

write(message: bytearray | str | bytes) int

Sends the given buffer to the other Brian.

Parameters:

message – str, bytearray or bytes buffer containing the actual message.

Returns:

number of bytes written

Raises:

OSError – If an error occurs during the write operation.

Error Codes: MP_EIO: BrianBrianComm is not ready or is disconnected.