bpod_base— Bpod Base

Implementation

class pybpodapi.bpod.bpod_base.BpodBase(serial_port=None, sync_channel=None, sync_mode=None, net_port=None)[source]

API to interact with Bpod

Variables:
  • session (Session) – Session for this bpod running experiment
  • hardware (Hardware) – Hardware object representing Bpod hardware
  • message_api (MessageAPI) – Abstracts communication with Bpod box
  • new_sma_sent (bool) – whether a new state machine was already uploaded to Bpod box
class Events[source]
class OutputChannels[source]
class ChannelTypes[source]
class ChannelNames[source]
loop_handler()[source]

handler that will execute on every loop when the bpod is running

open()[source]

Starts Bpod.

Connect to Bpod board through serial port, test handshake, retrieve firmware version, retrieve hardware description, enable input ports and configure channel synchronization.

Example:

my_bpod = Bpod().open("/dev/tty.usbmodem1293", "/Users/John/Desktop/bpod_workspace", "2afc_protocol")
Parameters:
  • serial_port (str) – serial port to connect
  • workspace_path (str) – path for bpod output files (no folders will be created)
  • session_name (str) – this name will be used for output files
  • baudrate [optional] (int) – baudrate for serial connection
  • sync_channel [optional] (int) – Serial synchronization channel: 255 = no sync, otherwise set to a hardware channel number
  • sync_mode [optional] (int) – Serial synchronization mode: 0 = flip logic every trial, 1 = every state
Returns:

Bpod object created

Return type:

pybpodapi.model.bpod

close()[source]

Close connection with Bpod

send_state_machine(sma, run_asap=None)[source]

Builds message and sends state machine to Bpod

Parameters:sma (pybpodapi.model.state_machine) – initialized state machine
run_state_machine(sma)[source]

Adds a new trial to current session and runs state machine on Bpod box.

While state machine is running, messages are processed accordingly.

When state machine stops, timestamps are updated and trial events are processed.

Finally, data is released for registered data consumers / exporters.

:param (pybpodapi.state_machine.StateMachine) sma: initialized state machine

load_serial_message(serial_channel, message_ID, serial_message)[source]

Load serial message on Bpod

Parameters:
  • serial_channel (int) – Serial port to send, 1, 2 or 3
  • message_ID (int) – Unique id for the message. Should be between 1 and 255
  • serial_message (list(int)) – Message to send. The message should be bigger than 3 bytes.
reset_serial_messages()[source]

Reset serial messages to equivalent byte codes (i.e. message# 4 = one byte, 0x4)

softcode_handler_function(data)[source]

Users can override this function directly on the protocol to handle a softcode from Bpod

Parameters:data (int) – soft code number
find_module_by_name(name)[source]

Search for a module by name

_BpodBase__process_opcode(sma, opcode, data, state_change_indexes)

Process data from bpod board given an opcode

In original bpod, sma.raw_data == raw_events

Parameters:
  • sma – state machine object
  • opcode (int) – opcode number
  • data – data from bpod board
  • state_change_indexes
Returns:

_BpodBase__update_timestamps(sma, state_change_indexes)

Read timestamps from Bpod and update state machine info

Parameters:
  • sma (StateMachine) –
  • state_change_indexes (list) –