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 Board

  • bc: 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:

  1. Board Control (`bc`): A BoardControl instance is created for managing the communication with the board.

  2. Available Commands (`commands`): This dictionary provides a list of commands with their descriptions and required parameters.

  3. 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.

  • port: Device name (LSL name)

  • device_type: Type of device (default: LSL).

  • template_name: Name of the connection template (default: template_lsl).

  • callback: Callback mechanism for the connection (default: dashboard).

disconnect_device

Disconnects a connected device. Requires:

  • port: device name (LSL name)

  • device_type: Type of device (default: LSL).

error

Represents an error message. Indicates invalid commands or server errors.

  • message: Description of the error.

get_devices

Returns a list of active devices.

start_recording

Starts recording data. Requires:

  • dir: Directory to save the recording.

  • subject: Subject ID (default: 1).

  • session: Session ID (default: 1).

  • run: Run number (default: 1).

  • task: Task description.

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#

  1. 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")
  1. Get connected devices:

import brainaccess_board as bb
bc, commands, status = bb.msg_connect()
command = commands["get_devices"]
reply = bc.command(command)
print(reply)
  1. 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)
  1. 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)