BpodBase
- class BpodBase(serial_port=None, sync_channel=None, sync_mode=None, net_port=None)[source]
Bases:
object
API to interact with Bpod
- Variables:
uploaded to Bpod box
- __init__(serial_port=None, sync_channel=None, sync_mode=None, net_port=None)[source]
Methods
__init__
([serial_port, sync_channel, ...])close
()Close connection with Bpod
create_session
()echo_softcode
(softcode)find_module_by_name
(name)Search for a module by name
handle_inline
(inline, sma)load_message
(module_index, msg)load_serial_message
(serial_channel, ...)Load serial message on Bpod
handler that will execute on every loop when the bpod is running
open
()Starts Bpod.
pause
()refresh_modules
()register_value
(name, value)Reset serial messages to equivalent byte codes (i.e. message# 4 = one byte, 0x4).
resume
()run_state_machine
(sma)Adds a new trial to current session and runs state machine on Bpod box.
send_state_machine
(sma[, run_asap])Builds message and sends state machine to Bpod
Users can override this function directly on the protocol to handle a softcode from Bpod
stop_trial
()trigger_event
(event_index, event_data)trigger_input
(channel_number, value)trigger_output
(channel_number, value)trigger_softcode
(softcode)Attributes
CHECK_STATE_MACHINE_COUNTER
hardware
modules
session
skip_all_trials
- class ChannelNames[source]
Bases:
ChannelName
- BNC = 'BNC'
BNC channel
- PWM = 'PWM'
Analog channel with PWM support (e.g. Led)
- SERIAL = 'Serial'
Serial channel
- VALVE = 'Valve'
Analog channel for connecting a valve
- WIRE = 'Wire'
Wire channel
- class ChannelTypes[source]
Bases:
ChannelType
- INPUT = 1
Input channel
- OUTPUT = 2
Output channel
- class Events[source]
Bases:
EventName
- BNC1High = 'BNC1High'
BNC
- Condition1 = '_Condition1'
Condition
- GlobalCounter1End = '_GlobalCounter1_End'
GlobalCounter_End
- GlobalTimer1End = '_GlobalTimer1_End'
GlobalTimer_End
- GlobalTimer1Start = '_GlobalTimer1_Start'
GlobalTimer_Start
- PA1_Port1In = 'PA1_Port1In'
Extension in port1
- Port1In = 'Port1In'
Port
- Tup = '_Tup'
Tup
- Wire1High = 'Wire1High'
Wire
- static is_condition(event_name)
- Parameters:
event_name (str)
- Return type:
bool
- static is_global_counter_end(event_name)
- Parameters:
event_name (str)
- Return type:
bool
- static is_global_timer_cancel(event_name)
- Parameters:
event_name (str)
- Return type:
bool
- static is_global_timer_end(event_name)
- Parameters:
event_name (str)
- Return type:
bool
- static is_global_timer_start(event_name)
- Parameters:
event_name (str)
- Return type:
bool
- static is_global_timer_trigger(event_name)
- Parameters:
event_name (str)
- Return type:
bool
- static is_state_timer(event_name)
- Parameters:
event_name (str)
- Return type:
bool
- class OutputChannels[source]
Bases:
OutputChannel
- BNC1High = ('BNC1', 3)
BNC
- GlobalCounterReset = '_GlobalCounterReset'
GlobalCounterReset
- GlobalTimer1Cancel = ('_GlobalTimerCancel', 1)
GlobalTimerCancel
- GlobalTimer1Trig = ('_GlobalTimerTrig', 1)
GlobalTimerTrig
- Serial1 = 'Serial1'
Serial
- SoftCode1 = ('SoftCode', 1)
SoftCode
- Valve = 'Valve'
Valve
- Wire1High = ('Wire1', 3)
Wire
- close()[source]
Close connection with Bpod
- find_module_by_name(name)[source]
Search for a module by name
- 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.
- 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) :param str session_name: this name will be used for output files :param int baudrate [optional]: baudrate for serial connection :param int sync_channel [optional]: Serial synchronization channel: 255 = no sync, otherwise set to a hardware channel number :param int sync_mode [optional]: Serial synchronization mode: 0 = flip logic every trial, 1 = every state :return: Bpod object created :rtype: pybpodapi.model.bpod
- reset_serial_messages()[source]
Reset serial messages to equivalent byte codes (i.e. message# 4 = one byte, 0x4)
- 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.
See also
Send command “run state machine”:
pybpodapi.bpod.bpod_base.BpodBase.run_state_machine()
.Process opcode:
pybpodapi.bpod.bpod_base.BpodBase._BpodBase__process_opcode()
.Update timestamps:
pybpodapi.bpod.bpod_base.BpodBase._BpodBase__update_timestamps()
.:param (
pybpodapi.state_machine.StateMachine
) sma: initialized state machine
- 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
- 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