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
-
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
-
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:
-
_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_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_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: Return type:
-
_bpodcom_override_input_state
(channel_number, value)[source]¶ Manually set digital value on channel
Parameters:
-
_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
-
_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