Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Stream EXG

Applies to: Instinct and xSys. Not available on xBud.

The eeg feature delivers continuous ADC samples. Confirm electrode contact first: a stream from a poorly seated electrode records noise that no later processing recovers. See Measure contact impedance.

The lifecycle and frame format are described in Stream lifecycle. This page applies them.

Note: The feature name passed to the SDK is "eeg", not "exg". The signal is EXG; the API identifier kept the older spelling.

Start a stream

const streamId = 20;

await client.features.executeOperation("eeg", "add_stream", {
  stream: {
    stream_id: streamId,
    protocol: "websocket",
    host: "127.0.0.1",
    port: 9020,
    elements_before_flush: 80,
  },
});

// Let the stream server bind.
await new Promise((resolve) => setTimeout(resolve, 1000));
import asyncio

stream_id = 20

await client.execute_operation("eeg", "add_stream", {
    "stream": {
        "stream_id": stream_id,
        "protocol": "websocket",
        "host": "127.0.0.1",
        "port": 9020,
        "elements_before_flush": 80,
    },
})

# Let the stream server bind.
await asyncio.sleep(1)
Field
Type
Description

stream_id

number

Identifier used by every later operation

protocol

"websocket"

Transport for stream frames

host

string

Bind address, usually 127.0.0.1

port

number

Port for the stream server

buffer_size

number

Optional transport buffer size

elements_before_flush

number

Samples per batch

At 4 kHz, elements_before_flush: 80 gives a batch every 20 ms.

Note: The SDK sets stream_type from the feature name. Do not set it yourself.

Receive samples

adc_data is a signed 24-bit sample, already sign-extended, so a negative value reads as negative.

channel_id is the absolute channel, combining the ADC and its local channel. Which physical electrode that corresponds to is set by the Synap register's connected_nerv_id and connected_nerv_channel_id. See Configure channels.

Keep the callback fast

At 4 kHz with 80-sample batches the callback runs about 50 times a second. Work done inside it delays every other operation on the event loop.

Hand frames off rather than processing them in place:

An unbounded queue grows without limit if the consumer is slower than the device. Cap it and count drops rather than letting memory climb through a long recording.

Stop and clean up

Unsubscribe with the feature and operation used to subscribe, which are "eeg" and "stream".

Warning: A stream that is not removed keeps the device transmitting after the process exits. Put these four calls in a finally block.

Change configuration without restarting

update_stream adjusts a running stream:

Complete example

Next steps

Last updated

Was this helpful?