Pure Python interface to Blackrock Neurotech Cerebus devices
Project description
pycbsdk
Pure Python package for communicating with Blackrock Cerebus devices
Quick Start
From a shell...
pip install pycbsdk
Then in python
from pycbsdk import cbsdk
params_obj = cbsdk.create_params()
nsp_obj = cbsdk.get_device(params_obj)
err = cbsdk.connect(nsp_obj)
config = cbsdk.get_config(nsp_obj)
print(config)
You may also try the provided test script with python -m pycbsdk.examples.print_rates
or via the shortcut: pycbsdk_print_rates
.
Introduction
pycbsdk
is a pure Python package for communicating with a Blackrock Neurotech Cerebus device. It is loosely based on Blackrock's cbsdk
, but shares no code nor is pycbsdk
supported by Blackrock.
pycbsdk
's API design is intended to mimic that of a C-library. Indeed, a primary goal of this library is to help prototype libraries in other languages. After all, Python is a poor choice to handle high throughput data without some compiled language underneath doing all the heavy lifting.
However, it's pretty useful as is! And so far it has been good-enough for some quick test scripts, and it even drops fewer packets than CereLink. So, please use it, and contribute! We are more than happy to see the API expand to support more features, or even to have an additional "pythonic" API.
Design
When the connection to the device is established, two threads are created and started:
CerebusDatagramThread
- Retrieves datagrams using
asyncio
- Slices into generic packets
- Casts packets into their native type
- Enqueues packets for the PacketHandlerThread
- Retrieves datagrams using
PacketHandlerThread
- Updates device state (e.g., mirrors device time)
- Calls registered callbacks depending on the packet type.
The device also registers some of its own internal callbacks to monitor config state.
The client can use API functions to:
- Get / Set config -- these might simply grab the internal state or they might warrant a roundtrip communication to the device.
- The latter may hold back the return value until the reply packet has been received and can therefore be slow. Try to call
get_config
withforce_refresh=True
sparingly.
- The latter may hold back the return value until the reply packet has been received and can therefore be slow. Try to call
- Register a callback to receive data as soon as it appears on the handler thread.
This and more should appear in the documentation at some point in the future...
Limitations
- This library takes exclusive control over the UDP socket on port 51002 and thus cannot be used with Central, nor any other instance of
pycbsdk
. You only get one instance ofpycbsdk
or Central per machine. - The API is still very sparse and limited in functionality.
- For now, Python still has the GIL. This means that despite using threading, if your callback functions are slow and hold up the PacketHandlerThread, this could hold up datagram retrieval and ultimately cause packets to be dropped.
- A possible solution is for your callbacks to simply enqueue the data for a longer-running process to handle.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pycbsdk-0.1.0.tar.gz
.
File metadata
- Download URL: pycbsdk-0.1.0.tar.gz
- Upload date:
- Size: 36.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5d53224b9cb433f1a5dadefad0d3a8ad73562e13a39662e3374c3ac25eb7a25 |
|
MD5 | 41d6039888815fe7a63c0dcd7f7a8115 |
|
BLAKE2b-256 | eaabd0de2e550a60599dfa66ed01ebfdba37b9a1f251c6186418ab8aadd3a5a0 |
File details
Details for the file pycbsdk-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: pycbsdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 46.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1bdfd4e75899ce876c1d7ded0c1db5762005fbb0867327673b4cf16e3a5a78d |
|
MD5 | 3c319944d76cb75810a2114eeaa5e0e2 |
|
BLAKE2b-256 | db7098f9b60cee4083040227d14d2d40a32e33b3e187a1978573a59f17b95937 |