brainaccess.core package

Submodules

brainaccess.core.annotation module

class brainaccess.core.annotation.Annotation[source]

Bases: Structure

Object containing annotation information

timestamp

Sample number corresponding to the time the annotation was recorded

annotation

Annotation text

property annotation
timestamp

Structure/Union member

brainaccess.core.battery_info module

class brainaccess.core.battery_info.BatteryInfo[source]

Bases: Structure

Object containing standard battery information

level

Battery charge percentage, 0-100

is_charger_connected

True if charger is connected to the device

is_charging

True if battery is charging

is_charger_connected

Structure/Union member

is_charging

Structure/Union member

level

Structure/Union member

brainaccess.core.device_features module

class brainaccess.core.device_features.DeviceFeatures(device_info)[source]

Bases: object

The DeviceFeatures class allowing the user to check what features a particular device supports.

Gets an instance of DeviceFeatures for the corresponding DeviceInfo class.

Parameters:

device_info (DeviceInfo) – Device for which to get features. Serial number is ignored.

electrode_count()[source]

Gets the number of EEG/EMG electrodes supported by the device.

Returns:

Number of electrodes

Return type:

int

has_gyro()[source]

Whether or not the device can capture gyroscope data.

Returns:

True if device has a gyroscope, False otherwise

Return type:

bool

is_bipolar()[source]

Whether or not the device’s electrodes are bipolar. Bipolar electrodes have separate P (positive) and N (negative) contacts.

Returns:

True if electrodes are bipolar, False otherwise

Return type:

bool

brainaccess.core.device_info module

class brainaccess.core.device_info.DeviceInfo[source]

Bases: Structure

Object containing device information

id

Device model number

hardware_version

Hardware version

firmware_version

Firmware version

serial_number

Device serial number

property device_model
firmware_version

Structure/Union member

hardware_version

Structure/Union member

serial_number

Structure/Union member

brainaccess.core.device_model module

class brainaccess.core.device_model.DeviceModel(value)[source]

Bases: Enum

Device model information

MINI_V2

BrainAccess MINI V2

MIDI

BrainAccess MIDI (16 Channels)

MAXI

BrainAccess MAXI (32 Channels)

EMG

BrainAccess EMG

HALO

BrainAccess Halo

UNKNOWN

Unknown device

EMG = 3
HALO = 4
MAXI = 2
MIDI = 1
MINI = 0
UNKNOWN = 255

brainaccess.core.eeg_channel module

Starting addresses of channels in the chunk

brainaccess.core.eeg_channel.SAMPLE_NUMBER

The number of the sample starting from 0 at stream start

brainaccess.core.eeg_channel.ELECTRODE_MEASUREMENT

EEG electrode measurement value (uV)

brainaccess.core.eeg_channel.ELECTRODE_CONTACT

Whether or not the electrode is making contact with the skin

brainaccess.core.eeg_channel.DIGITAL_INPUT

Digital IO pin

brainaccess.core.eeg_channel.ACCELEROMETER

Accelerometer values

Examples

To get ACCELEROMETER x y and z index in the chunk

  • x: get_channel_index(ACCELEROMETER + 0)

  • y: get_channel_index(ACCELEROMETER + 1)

  • z: get_channel_index(ACCELEROMETER + 2)

brainaccess.core.eeg_manager module

class brainaccess.core.eeg_manager.EEGManager[source]

Bases: object

The EEG manager is the primary tool for communicating with the BrainAccess device. Note that the EEG manager is not thread-safe.

Creates an EEG Manager.

Warning

Make sure the core library has been initialized first!

annotate(annotation: str)[source]

Adds an annotation at the current time

Warning

Annotations are cleared on disconnect

Parameters:

annotation (str) – annotation text

clear_annotations()[source]

Clears annotations

connect(port: str)[source]

Connects to a device via COM port and attempts to initialize it.

Note

This function runs asynchronously.

Parameters:

port (str) – COMx on Windows and /dev/rfcommX on Linux decided upon connecting device to Bluetooth

Returns:

future – await future to complete connecting

Return type:

asyncio.Future

destroy()[source]

Destroys an EEG manager instance.

Warning

Must be called exactly once, after the manager is no longer needed

disconnect()[source]

Disconnects the EEGManager from the EEG device, if connected

get_annotations()[source]

Retrieve all the accumulated annotations

Warning

Annotations are cleared on disconnect

Returns:

list of annotations

Return type:

list

get_battery_info()[source]

Returns a structure containing standard battery information from the device

Returns:

Battery information from the EEG device

Return type:

BatteryInfo

get_channel_index(channel: int)[source]

Gets the index of a channel’s data into the chunk

Get the index into the array provided by the chunk callback that contains the data of the channel number specified

Parameters:

channel (int) – The number of the channel whose index to get

Returns:

Index into chunk representing a channel

Return type:

int

get_device_info()[source]

Get device information

Warning

Must not be called unless device connection is successful

Returns:

device model, version, firmware version and buffer size

Return type:

DeviceInfo

get_full_battery_info()[source]

Returns a structure containing extended battery info from the device

Note

This function runs asynchronously.

Returns:

future – awaiting future returns FullBatteryInfo

Return type:

asyncio.Future

get_latency()[source]

Measure approximate communication latency with the device

Note

This function runs asynchronously.

Returns:

future – awaiting future returns number of seconds (float)

Return type:

asyncio.Future

get_sample_frequency()[source]

Get device sampling frequency

Returns:

Sample frequency (Hz)

Return type:

int

is_connected()[source]

Checks if the EEGManager is currently connected to an EEG device

Returns:

True if connected, False otherwise

Return type:

bool

is_streaming()[source]

Checks if the device is streaming

Returns:

True if the stream is active, False otherwise

Return type:

bool

set_callback_battery(f)[source]

Sets a callback to be called every time the battery status is updated

Warning

The callback may or may not run in the reader thread, and as such, synchronization must be used to avoid race conditions, and the callback itself must be as short as possible to avoid blocking communication with the device.

Parameters:

f – pass callback Function to be called every time a battery update is available Set to null to disable.

set_callback_chunk(f)[source]

Sets a callback to be called every time a chunk is available

Warning

The callback may or may not run in the reader thread, and as such, synchronization must be used to avoid race conditions, and the callback itself must be as short as possible to avoid blocking communication with the device.

Parameters:

f – callback Function to be called every time a chunk is available Set to null to disable.

set_callback_disconnect(f)[source]

Sets a callback to be called every time the device disconnects

Warning

The callback may or may not run in the reader thread, and as such, synchronization must be used to avoid race conditions, and the callback itself must be as short as possible to avoid blocking communication with the device.

Parameters:

f – callback Function to be called every time the device disconnects. Set to null to disable.

set_channel_bias(self, channel: int, bias: bool)[source]

DEPRECATED: use the version with Polarity instead.

Set an electrode channel as a bias electrode Essentially the signals of these channels are inverted and injected into the bias channel/electrode. This helps in reducing common mode noise such as noise coming from the mains. Only select channels for bias feedback that have good contact with a skin. Typically one channel is sufficient for bias feedback to work effectively.

This function takes effect on stream start, and its effects are reset by stream stop. Therefore, it must be called with the appropriate arguments before every stream start.

channel: int

Channel ID (brainaccess.core.eeg_channel) to set/unset as bias channel

bias: bool

True to enable channel, False to disable.

set_channel_bias(self, channel: int, p: brainaccess.core.polarity.Polarity)
Set an electrode channel as a bias electrode

Essentially the signals of these channels are inverted and injected into the bias channel/electrode. This helps in reducing common mode noise such as noise coming from the mains. Only select channels for bias feedback that have good contact with a skin. Typically one channel is sufficient for bias feedback to work effectively.

This function takes effect on stream start, and its effects are reset by stream stop. Therefore, it must be called with the appropriate arguments before every stream start.

channel: int

Channel ID (brainaccess.core.eeg_channel) to set/unset as bias channel

p: Polarity

Which side of the electrode to use (if device is not bipolar, use BOTH)

set_channel_enabled(channel: int, state: bool)[source]

Enables or disables the channel on the device

Warning

Enabled channels are reset by stream stop. Must be called with the appropriate arguments before every stream start

Parameters:
  • channel (int) – Channel ID (brainaccess.core.eeg_channel) to enable/disable.

  • state (bool) – True to enable channel, False to disable.

set_channel_gain(channel: int, gain: GainMode)[source]

Changes gain mode for a channel on the device. Setting gain values to lower will increase the measured voltage range, but would decrease the amplitude resolution, 12 is the optimum in most cases.

Warning

This function takes effect on stream start, and its effects are reset by stream stop. Therefore, it must be called with the appropriate arguments before every stream start. This only affects channels that support it. For example, it affects the electrode measurement channels but not sample number or digital input.

Parameters:
  • channel (int) – Channel ID (brainaccess.core.eeg_channel) whose gain to modify.

  • gain (GainMode) – Gain mode. Default X12

set_impedance_mode(mode: ImpedanceMeasurementMode)[source]

Sets impedance measurement mode This function setups device for electrode impedance measurement. It injects a 7nA certain frequency current through the bias electrodes to measurement electrodes. Voltage recordings from each channel can then be used to calculate the impedance for each electrode: Impedance = Vpp/7nA

Warning

This function takes effect on stream start, and its effects are reset by stream stop. Therefore, it must be called with the appropriate arguments before every stream start.

Parameters:

mode (ImpedanceMeasurementMode) – Impedance mode to set

set_io(pin: int, state: bool)[source]

Digital pin control The digital input pin, which by default is pulled high but can be pulled low by an external sensor, can also be pulled low by the device itself. By default, upon powering up or connecting/disconnecting the device, the digital input pin is pulled high.

This can be useful, for example, in case you want to synchronize devices: connect device A and B’s digital inputs, start both streams, then set A’s digital input to pull low, which also pulls B’s input with it. The falling edge can be recorded from both streams, and the data can then be aligned accordingly.

This can also be used for low-speed communication with external devices, controlling LEDs via a mosfet, etc.

Note

This function runs asynchronously.

Parameters:
  • pin (int) – Number of digital input pin of the EEG device to set the IO state of (starting from 0)

  • state (bool) – True to pull high, False to pull to ground

Returns:

future – awaiting future sets digital pin state

Return type:

asyncio.Future

start_stream()[source]

Starts streaming data from the device

Note

This function runs asynchronously.

Warning

You must not call this function twice without stopping the stream in between.

Returns:

future – awaiting future starts stream

Return type:

asyncio.Future

stop_stream()[source]

Stops streaming data from the device

Note

This function runs asynchronously.

Warning

You must not call this function twice without starting the stream in between. You must not call this function while the stream is not running. Calling this function resets all stream settings. If you want to stream again afterwards, you must re-enable all the channels, biases, gains, and impedance measurement mode that you set previously.

Returns:

future – awaiting future stops stream

Return type:

asyncio.Future

brainaccess.core.full_battery_info module

class brainaccess.core.full_battery_info.FullBatteryInfo[source]

Bases: Structure

Object containing extended battery information .. attribute:: is_charging

True if battery is charging

is_charging

True if charger is connected to the device

level

Battery charge percentage, 0-100

health

Battery health percentage, 0-100

voltage

Battery voltage in volts

current

Current flow in amps (negative means discharge)

current

Structure/Union member

health

Structure/Union member

is_charger_connected

Structure/Union member

is_charging

Structure/Union member

level

Structure/Union member

voltage

Structure/Union member

brainaccess.core.gain_mode module

class brainaccess.core.gain_mode.GainMode(value)[source]

Bases: Enum

Gain mode multipliers

X1

1x gain

X2

2x gain

X4

4x gain

X6

6x gain

X8

8x gain

X12

12x gain

X24

24x gain

UNKNOWN

OxFF gain

UNKNOWN = 255
X1 = 0
X12 = 5
X2 = 1
X24 = 6
X4 = 2
X6 = 3
X8 = 4
brainaccess.core.gain_mode.gain_mode_to_multiplier(gain_mode)[source]

Converts gain mode to integer multiplier representing the gain mode

Parameters:

gain_mode (GainMode) –

Returns:

integer multiplier representing the gain mode (ex: X12 returns 12)

Return type:

int

brainaccess.core.gain_mode.multiplier_to_gain_mode(multiplier)[source]

Converts multiplier to the gain mode

Parameters:

multiplier (int) –

Return type:

GainMode

brainaccess.core.impedance_measurement_mode module

Modes to be used for impedance measurement

class brainaccess.core.impedance_measurement_mode.ImpedanceMeasurementMode(value)[source]

Bases: Enum

OFF

No active impedance measurement

HZ_7_8

7.9 Hz wave

HZ_31_2

31.2 Hz wave

DR_DIV4

Wave frequency of sample_rate/4

DR_DIV4 = 3
HZ_31_2 = 2
HZ_7_8 = 1
OFF = 0

brainaccess.core.polarity module

class brainaccess.core.polarity.Polarity(value)[source]

Bases: Enum

An enumeration.

BOTH = 1
NEGATIVE = 3
NONE = 0
POSITIVE = 2

brainaccess.core.version module

class brainaccess.core.version.Version(major, minor, patch)[source]

Bases: Structure

Object describing version numbers

major

API-breaking changes

minor

Feature updates

patch

Bugfixes

major

Structure/Union member

minor

Structure/Union member

patch

Structure/Union member

brainaccess.core.version.is_version_compatible(expected, actual)[source]

Check if versions are compatible

Parameters:
  • expected (str) –

  • actual (str) –

Returns:

True if compatible

Return type:

bool

Module contents

brainaccess.core.close()[source]

Closes the library and cleans up afterwards.

Warning

Must be called after all BrainAccess Core library functions used by the application. Only call once. If initialization failed, do not call this function.

brainaccess.core.get_version()[source]

Returns the installed library’s actual version

brainaccess.core.init(expected_version)[source]

Initializes the library This function reads the config file, starts logging, etc. It first checks if the version of the library that the application expects and the version of the library installed are compatible.

Parameters:

version – The version of the library that the application expects.

Warning

Must bet called before any other BrainAccess Core library function. Only call once.