bpod
Functions
|
Initializes and returns a PyBpod instance. |
Classes
- class SoftCode[source]
Bases:
objectHandles UDP SoftCode communication.
- client_socket
The UDP socket.
- Type:
socket.socket
- address
The (ip, port) address for UDP communication.
- Type:
tuple
- send(idx: int) None[source]
Sends a SoftCode to the configured address.
- Parameters:
idx (int) – The softcode index to send.
- kill() None[source]
Sends a kill signal to stop the current session.
- close() None[source]
Closes the UDP socket.
- class PyBpod[source]
Bases:
PyBpodBaseInterface for controlling Bpod devices.
- bpod
The Bpod device instance.
- Type:
Bpod
- sma
The state machine instance.
- Type:
StateMachine
- softcode
The SoftCode handler.
- Type:
- session
The current Bpod session.
- Type:
village.pybpodapi.session.Session | Any
- connected
Connection status.
- Type:
bool
- error
Error message if any.
- Type:
str
- functions
List of callback functions for softcodes.
- Type:
list[Callable]
- add_state(state_name: Any, state_timer: float = 0, state_change_conditions: Any = {}, output_actions: Any = ()) None[source]
Adds a state to the state machine.
- Parameters:
state_name (Any) – The name of the state.
state_timer (float) – Duration of the state in seconds.
state_change_conditions (Any) – Dictionary of events that trigger state transitions.
output_actions (Any) – Actions to perform when entering the state.
- set_global_timer(timer_id: Any, timer_duration: Any, on_set_delay: int = 0, channel: Any | None = None, on_message: int = 1, off_message: int = 0, loop_mode: int = 0, loop_intervals: int = 0, send_events: int = 1, oneset_triggers: Any | None = None) None[source]
Sets a global timer.
- Parameters:
timer_id (Any) – The ID of the timer.
timer_duration (Any) – The duration of the timer.
on_set_delay (int) – Delay before setting the timer.
channel (Any | None) – The channel associated with the timer.
on_message (int) – Message to send when timer starts.
off_message (int) – Message to send when timer ends.
loop_mode (int) – Loop mode configuration.
loop_intervals (int) – Number of loop intervals.
send_events (int) – Whether to send events.
oneset_triggers (Any | None) – Triggers to set once.
- set_condition(condition_number: Any, condition_channel: Any, channel_value: Any) None[source]
Sets a condition for the state machine.
- Parameters:
condition_number (Any) – The identifier for the condition.
condition_channel (Any) – The channel to check.
channel_value (Any) – The value to check against.
- set_global_counter(counter_number: Any, target_event: Any, threshold: Any) None[source]
Sets a global counter.
- Parameters:
counter_number (Any) – The ID of the counter.
target_event (Any) – The event to count.
threshold (Any) – The count threshold.
- create_state_machine() None[source]
Creates a new state machine instance.
- send_and_run_state_machine() None[source]
Sends and runs the current state machine on the Bpod.
- register_value(name: str, value: Any) None[source]
Registers a value with the Bpod session.
- Parameters:
name (str) – The name of the value.
value (Any) – The value to register.
- receive_softcode(idx: int) None[source]
Handles receiving a softcode and forwarding it via SoftCode sender.
- Parameters:
idx (int) – The softcode index.
- manual_override_input(message: str) None[source]
Manually overrides an input channel.
- Parameters:
message (str) – The override message string.
- manual_override_output(message: str | tuple) None[source]
Manually overrides an output channel.
- Parameters:
message (str | tuple) – The override message string or tuple.
- softcode_handler_function(data: int) None[source]
Handles regular softcode callbacks.
- Parameters:
data (int) – The softcode data value (1-99).
- connect(functions: list[Callable]) None[source]
Connects to the Bpod and initializes session.
- Parameters:
functions (list[Callable]) – List of callback functions for softcodes.
- led(i: int, close: bool) None[source]
Triggers an LED in a separate thread.
- Parameters:
i (int) – LED index.
close (bool) – Whether to close connection after triggered.
- led_thread(i: int, close: bool) None[source]
Thread function to blink an LED.
- Parameters:
i (int) – LED index.
close (bool) – Whether to close connection after.
- water(i: int, close: bool) None[source]
Triggers a water valve in a separate thread.
- Parameters:
i (int) – Valve index.
close (bool) – Whether to close connection.
- water_thread(i: int, close: bool) None[source]
Thread function to open and close a water valve.
- Parameters:
i (int) – Valve index.
close (bool) – Whether to close connection.
- poke(i: int, close: bool) None[source]
Simulates a poke event in a separate thread.
- Parameters:
i (int) – Poke port index.
close (bool) – Whether to close connection.
- poke_thread(i: int, close: bool) None[source]
Thread function to simulate poke entry and exit.
- Parameters:
i (int) – Poke port index.
close (bool) – Whether to close connection.
- clean() None[source]
Runs a cleanup state machine that exits immediately.
- stop() None[source]
Stops the current session and closes connections.
- close() None[source]
Closes the Bpod connection.
- get_bpod() PyBpodBase[source]
Initializes and returns a PyBpod instance.
- Returns:
An instance of PyBpod or a dummy base class on failure/Sphinx.
- Return type: