Skip to main content

Pure Python interface to Blackrock Neurotech Cerebus devices

Project description

PyPI version

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)  # NSPDevice instance. This will be the first argument to most API calls. 
runlevel = cbsdk.connect(nsp_obj)  # Bind sockets, change device run state, and get device config.
config = cbsdk.get_config(nsp_obj)
print(config)

You may also try one of the provided test scripts

  • python -m pycbsdk.examples.print_rates or via the entrypoint pycbsdk-rates.
  • python -m pycbsdk.examples.comments

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

Alt text

Upon initialization, the NSPDevice instance configures its sockets (but no connection yet), it allocates memory for its mirror of the device state, and it registers callbacks to monitor config state.

When the connection to the device is established, two threads are created and started:

  • CerebusDatagramThread
    • Makes heavy use of asyncio
      • A Receiver Coroutine retrieves datagrams, slices into generic packets, enqueues them in the receiver queue
      • A Sender Coroutine monitors a sender queue and immediately sends found packets.
  • PacketHandlerThread
    • Monitors the receiver queue.
    • Updates device state (e.g., mirrors device time)
    • Materializes the generic packets into specific packets.
    • Calls registered callbacks depending on the packet type.

connect() has startup_sequence=True by default. This will cause the SDK to attempt to put the device into a running state. Otherwise, it'll stay in its original run state.

After the connection is established, the client can use API functions to:

  • Get / Set config
    • set_config and set_channel_config do not do anything yet
    • set_channel_spk_config and set_channel_config_by_packet do things and are blocking.
    • get_config is non-blocking by default and will simply read the local mirror of the config. However, if force_refresh=True is passed as a kwarg, then this function will block and wait for a reply from the device. Use this sparingly.
  • 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 of pycbsdk or Central per machine.
    • CereLink's cerebus.cbpy uses shared memory and therefore can work in parallel to Central or other cbpy instances.
  • The API is sparse but is filling out over time. Use the issue tracker to make requests for features that you need.
  • For now, our dependencies are not compatible with NoGIL Python 3.13. 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.
  • Socket configuration is still finicky and platform-specific. On Windows you might need to supply the address of the local adapter pycbsdk is binding (e.g., --client-addr 192.168.137.198), but on MacOS you must bind INADDR_ANY, or --client-addr 0.0.0.0, which is the default in most cases and can be omitted.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycbsdk-0.4.0.tar.gz (50.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycbsdk-0.4.0-py3-none-any.whl (54.2 kB view details)

Uploaded Python 3

File details

Details for the file pycbsdk-0.4.0.tar.gz.

File metadata

  • Download URL: pycbsdk-0.4.0.tar.gz
  • Upload date:
  • Size: 50.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.7

File hashes

Hashes for pycbsdk-0.4.0.tar.gz
Algorithm Hash digest
SHA256 8df67ff83dc49bf09a7192e3154858179f7122ea479f8dc861cb48920bf637c6
MD5 e3e6f22ec3f49c10b339a0f371d3d86a
BLAKE2b-256 7c0ea9b72bf233599b7efef6d21205bc289348edbe74a6a08ca7dd983307d807

See more details on using hashes here.

File details

Details for the file pycbsdk-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: pycbsdk-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 54.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.7

File hashes

Hashes for pycbsdk-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 02f9691b1fd72ad84beba606fd0cba7f3875044cfcf2aac331edaf95403edbc8
MD5 4d6015c037a4073c92dbac093486915a
BLAKE2b-256 6d59618756db13ed4083d425282508572efed2bc6c5ac299ece48bff990db298

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page