Skip to content

brian.sensors.BrianBrianComm

brian.sensors

BrianBrianComm class objects

class BrianBrianComm(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__

def __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.

Arguments:

  • 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

def available() -> int

Returns:

bytes available to be read

read

def read(size: Optional[int] = None) -> bytes

reads data incoming from the other Brian.

Arguments:

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

Raises:

  • OSError: If an error occurs during the write operation. Error Codes:
  • MP_EIO: BrianBrianComm is not ready or is disconnected.

Returns:

read bytes

write

def write(message: Union[bytearray, str, bytes]) -> int

Sends the given buffer to the other Brian.

Arguments:

  • message: str, bytearray or bytes buffer containing the actual message.

Raises:

  • OSError: If an error occurs during the write operation. Error Codes:
  • MP_EIO: BrianBrianComm is not ready or is disconnected.

Returns:

number of bytes written