bpod_core.bpod.Bpod

class bpod_core.bpod.Bpod

Bases: SerialDevice, AbstractBpod

Class for interfacing with a Bpod Finite State Machine.

__init__(port=None, serial_number=None, *, remote=False) None

Initialize the serial device.

Parameters:
  • port (str) – The serial port device path (e.g., ‘/dev/ttyUSB0’ or ‘COM3’).

  • serial_device_name (str, optional) – Name used to identify this device in log messages, by default 'serial_device'.

  • open_connection (bool, optional) – Whether to open the connection immediately, by default True.

  • **kwargs – Additional arguments for compatibility with subclasses.

  • serial_number (str | None)

  • remote (bool)

Raises:

serial.SerialException – If the specified port does not exist.

Return type:

None

close() None

Close the connection to the Bpod.

Raises:

SerialException – If the port could not be closed.

Return type:

None

open() None

Open the connection to the Bpod.

Raises:
  • SerialException – If the port could not be opened.

  • BpodError – If the handshake fails.

Return type:

None

reset_session_clock() bool

Reset the Bpod session clock to zero.

Returns:

True if the Bpod acknowledged the command.

Return type:

bool

run_state_machine(*, blocking=True) None

Run the previously sent state machine.

Parameters:

blocking (bool, optional) – If True (default), block until the state machine finishes. If False, return immediately after starting.

Raises:

RuntimeError – If a state machine is already running.

Return type:

None

send_state_machine(state_machine, *, run_asap=False, validate_only=False) None

Send a state machine to the Bpod.

This method compiles the provided state machine into a byte array format compatible with the Bpod and sends it to the device. It also validates the state machine for compatibility with the hardware before sending.

Parameters:
  • state_machine (StateMachine) – The state machine to be sent to the Bpod device.

  • run_asap (bool, optional) – If True, the state machine will run immediately after the current one has finished. Default is False.

  • validate_only (bool, optional) – If True, the state machine is only validated and not sent to the device. Default is False.

Raises:
  • ValueError – If the state machine is invalid or exceeds hardware limitations.

  • validate_callCallHintViolation – If function arguments don’t match type hints.

Return type:

None

set_status_led(enable) bool

Enable or disable the Bpod status LED.

Parameters:

enable (bool) – True to turn the LED on, False to turn it off.

Returns:

True if the Bpod acknowledged the command.

Return type:

bool

stop_state_machine() None

Stop the currently running state machine.

Return type:

None

update_modules() None

Update the list of connected modules and their configurations.

Return type:

None

validate_state_machine(state_machine) None

Validate the provided state machine for compatibility with the hardware.

Parameters:

state_machine (StateMachine) – The state machine to validate.

Raises:

ValueError – If the state machine is invalid or not compatible with the hardware.

Return type:

None

wait() None

Wait for the currently running state machine to finish.

Blocks until the state machine thread completes. If no state machine is currently running, this method returns immediately.

Return type:

None

actions: list[str]

List of output actions.

event_names: list[str]

List of event names.

inputs: NamedTuple

Available input channels.

property is_running: bool

Check if the Bpod is currently running a state machine.

property location: str | None

Get the location of the Bpod device.

modules: NamedTuple

Available modules.

property name: str | None

Get the name of the Bpod device.

outputs: NamedTuple

Available output channels.

property port: str

The name of the serial port.

Returns:

The device path of the serial port (e.g., ‘/dev/ttyACM0’).

Return type:

str

property serial0: ExtendedSerial

Primary serial device for communication with the Bpod.

serial1: ExtendedSerial | None = None

Secondary serial device for communication with the Bpod.

serial2: ExtendedSerial | None = None

Tertiary serial device for communication with the Bpod - used by Bpod 2+ only.

property serial_number: str

The Bpod’s unique serial number.

property version: VersionInfo

Version information of the Bpod’s firmware and hardware.