Board Control#
This section demonstrates how to establish a connection with Brainaccess Board and interact via messages.
For these examples to work, ensure that the BrainAccess Board is running and the device is properly connected.
import brainaccess_board as bb
# Connect to the message queue
bc, commands, status = bb.msg_connect()
Output:
INFO: Board Control created using port: 45975
The
msg_connect()
function creates connection with the Brainaccess Boardbc: The
BoardControl
object for interacting with the message queue.commands: A dictionary of available commands and their details.
status: Indicates whether the connection to the board was successful (True/False).
Example Objects:
Board Control (`bc`): A BoardControl instance is created for managing the communication with the board.
Available Commands (`commands`): This dictionary provides a list of commands with their descriptions and required parameters.
Connection Status (`status`): Indicates if the connection to the board was successful. Example:
Command Descriptions#
The commands dictionary provides a detailed list of all available commands for interacting with the BrainAccess Board. Each command includes its description, required parameters, and additional metadata.
Command |
Description |
---|---|
test |
Tests the connection to the board. |
commands |
Retrieves a list of all available commands. |
connect_device |
Connects to a device.
|
disconnect_device |
Disconnects a connected device. Requires:
|
error |
Represents an error message. Indicates invalid commands or server errors.
|
get_devices |
Returns a list of active devices. |
start_recording |
Starts recording data. Requires:
|
stop_recording |
Stops an ongoing recording. |
scan_bt |
Scans for available Bluetooth devices. |
status |
Retrieves the current status of the board. Provides additional status data if available. |
Each command is structured with additional metadata such as:
Command: Name of the command to execute.
Description: Explanation of what the command does.
Message: Optional feedback or status message.
Source: Indicates whether the command is issued by the client or server.
Data: Parameters or additional data required/returned by the command.
Examples#
Test Connection: Test the connection to the board.
import brainaccess_board as bb
bc, commands, status = bb.msg_connect()
command = commands["test"]
reply = bc.command(command)
if reply["message"] == "Connection successful":
print("Connection successful")
else:
print("Connection failed")
Get connected devices:
import brainaccess_board as bb
bc, commands, status = bb.msg_connect()
command = commands["get_devices"]
reply = bc.command(command)
print(reply)
Create Markers and connect - disconnect from the board:
import time
import brainaccess_board as bb
stimulation = bb.stimulation_connect(name="BrainAccessMarkers")
stim_name = stimulation._info.source_id()
stim_port = stimulation._outlet.get_info().uid()
# connect markers to the board
bc, commands, status = bb.msg_connect()
command = commands["connect_device"].copy()
command["port"] = stim_port
reply = bc.command(command)
print(reply)
time.sleep(5)
# disconnect markers from the board
command = commands["disconnect_device"].copy()
command["device_name"] = stim_name
command["device_type"] = "lsl"
command["port"] = stim_port
command["callback"] = "dashboard"
reply = bc.command(command)
print(reply)
Start and stop recording:
The physical button on the Brainaccess Board does not change
import time
import brainaccess_board as bb
bc, commands, status = bb.msg_connect()
command = commands["start_recording"].copy()
# command["dir"] = "path/to/save" # change to your dir
command["subject"] = 1
command["session"] = 1
command["run"] = 1
command["task"] = "task_name"
reply = bc.command(command)
print(reply)
time.sleep(4)
# stop recording
command = commands["stop_recording"]
reply = bc.command(command)
print(reply)