bpod_com_protocol— Bpod Communication Protocol

Implementation

class pybpodapi.bpod.bpod_com_protocol.BpodCOMProtocol(serial_port=None, sync_channel=None, sync_mode=None)[source]

Define command actions that can be requested to Bpod device.

Private attributes

_arcom

pybpodapi.com.arcom.ArCOM

ArCOM object that performs serial communication.

Methods

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

manual_override(channel_type, channel_name, channel_number, value)[source]

Manually override a Bpod channel

Parameters:
  • channel_type (ChannelType) – channel type input or output
  • channel_name (ChannelName) – channel name like PWM, Valve, etc.
  • channel_number
  • value (int) – value to write on channel
_bpodcom_connect(serial_port, baudrate=115200, timeout=1)[source]

Connect to Bpod using serial connection

Parameters:
  • serial_port (str) – serial port to connect
  • baudrate (int) – baudrate for serial connection
  • timeout (float) – timeout which controls the behavior of read()
_bpodcom_disconnect()[source]

Signal Bpod device to disconnect now

_bpodcom_handshake()[source]

Test connectivity by doing an handshake

Returns:True if handshake received, False otherwise
Return type:bool
_bpodcom_firmware_version()[source]

Request firmware and machine type from Bpod

Returns:firmware and machine type versions
Return type:int, int
_bpodcom_reset_clock()[source]

Reset session clock

_bpodcom_stop_trial()[source]

Stops ongoing trial (We recommend using computer-side pauses between trials, to keep data uniform)

_bpodcom_pause_trial()[source]

Pause ongoing trial (We recommend using computer-side pauses between trials, to keep data uniform)

_bpodcom_resume_trial()[source]

Resumes ongoing trial (We recommend using computer-side pauses between trials, to keep data uniform)

_bpodcom_get_timestamp_transmission()[source]

Return timestamp transmission scheme

_bpodcom_hardware_description(hardware)[source]

Request hardware description from Bpod

Parameters:hardware (Hardware) – hardware
_bpodcom_enable_ports(hardware)[source]

Enable input ports on Bpod device

Parameters:inputs_enabled (list[int]) – list of inputs to be enabled (0 = disabled, 1 = enabled)
Return type:bool
_bpodcom_set_sync_channel_and_mode(sync_channel, sync_mode)[source]

Request sync channel and sync mode configuration

Parameters:
  • sync_channel (int) – 255 = no sync, otherwise set to a hardware channel number
  • sync_mode (int) – 0 = flip logic every trial, 1 = every state
Return type:

bool

_bpodcom_echo_softcode(softcode)[source]

Send soft code

_bpodcom_manual_override_exec_event(event_index, event_data)[source]

Send soft code

_bpodcom_override_input_state(channel_number, value)[source]

Manually set digital value on channel

Parameters:
  • channel_number (int) – number of Bpod port
  • value (int) – value to be written
_bpodcom_send_softcode(softcode)[source]

Send soft code

_bpodcom_send_state_machine(message)[source]

Sends state machine to Bpod

Parameters:
  • message (list(int)) – TODO
  • ThirtyTwoBitMessage (list(int)) – TODO
_bpodcom_run_state_machine()[source]

Request to run state machine now

_bpodcom_read_trial_start_timestamp_seconds()[source]

A new incoming timestamp message is available. Read trial start timestamp in millseconds and convert to seconds.

Returns:trial start timestamp in milliseconds
Return type:float
_bpodcom_state_machine_installation_status()[source]

Confirm if new state machine was correctly installed

Return type:bool
data_available()[source]

Finds out if there is data received from Bpod

Return type:bool
_bpodcom_read_opcode_message()[source]

A new incoming opcode message is available. Read opcode code and data.

Returns:opcode and data
Return type:tuple(int, int)
_bpodcom_read_alltimestamps()[source]

A new incoming timestamps message is available. Read number of timestamps to be sent and then read timestamps array.

Returns:timestamps array
Return type:list(float)
_bpodcom_read_current_events(n_events)[source]

A new incoming events message is available. Read number of timestamps to be sent and then read timestamps array.

Parameters:n_events (int) – number of events to read
Returns:a list with events
Return type:list(int)
_bpodcom_load_serial_message(serial_channel, message_id, serial_message, n_messages)[source]

Load serial message on channel

:param TODO :rtype: bool

_bpodcom_reset_serial_messages()[source]

Reset serial messages on Bpod device

Return type:bool
_bpodcom_override_digital_hardware_state(channel_number, value)[source]

Manually set digital value on channel

Parameters:
  • channel_number (int) – number of Bpod port
  • value (int) – value to be written
_bpodcom_send_byte_to_hardware_serial(channel_number, value)[source]

Send byte to hardware serial channel 1-3

Parameters:
  • channel_number (int) –
  • value (int) – value to be written