RDA Client (rdaclient)

RDA client classes. See rdaclient.Client’s docstring for more information

class rdaclient.Client(buffer_size=300000, buffer_window=1)[source]

An asynchronous RDA (Remote Data Access) client with buffer. Spawns a child process for storing constantly incoming data in the background.

Currently supports only float32 data type

Parameters :

buffer_size : int, optional

buffer capacity (in samples)

buffer_window : int, optional

buffer pocket size (in samples)

Notes

The RDA data sharing is used by the BrainVision software.

Attributes

is_streaming Checks whether the Streamer is active, read-only (bool)
buffer_size Buffer capacity in samples, read-only (int)
data_dtype Buffer’s data type, read-only (string)
buffer_window Buffer pocket size, read-only (in samples)

Methods

connect(destaddr) Connects to an RDA server
disconnect() Disconnects the client from a server
get_data(sampleStart, sampleEnd) Gets the data from the buffer.
poll(nSamples[, timeout, sleep]) Gets the most resent data chunk from the buffer.
start_streaming([timeout]) Starts data streaming from the server, using the following algorithm: 1.
stop_streaming([write_timelog]) Stops streaming by sending corresponding signal to a Streamer process
wait(sampleStart, sampleEnd[, timeout, sleep]) Gets the data from the buffer.
buffer_size

Buffer capacity in samples, read-only (int)

buffer_window

Buffer pocket size, read-only (in samples)

connect(destaddr)[source]

Connects to an RDA server

Parameters :

destaddr : tuple

server address

data_dtype

Buffer’s data type, read-only (string)

disconnect()[source]

Disconnects the client from a server

get_data(sampleStart, sampleEnd)[source]

Gets the data from the buffer. If possible, the data is returned in the form of a numpy view on the corresponding chunk (without copy)

Parameters :

sampleStart : int

first sample index (included)

sampleEnd : int

last samples index (excluded)

Returns :

data : ndarray (view or copy) or None

data chunk or None, if the data is not available

is_streaming

Checks whether the Streamer is active, read-only (bool)

last_sample

Number of a last sample written to the buffer (= total no.)

poll(nSamples, timeout=10, sleep=0.00050000000000000001)[source]

Gets the most resent data chunk from the buffer. Blocks until the next data block is written to the buffer or timeout is over.

Parameters :

nSamples : int

chunk size (in samples)

timeout : float

timeout (seconds)

sleep : float

time to wait until the next loop iteration. Used to avoid 100% processor loading.

Returns :

data : ndarray (view or copy) or None

data chunk or None, if the data is overwritten or the timeout has expired

start_streaming(timeout=10)[source]

Starts data streaming from the server, using the following algorithm:

  1. Waits until start/data message arrives or timeout is over
  2. If start message arrived, initializes buffer
  3. Spawns a background process for data streaming
  4. Releases
Parameters :

timeout : float, optional

time to wait for a start message (in seconds)

stop_streaming(write_timelog=False)[source]

Stops streaming by sending corresponding signal to a Streamer process

Parameters :

write_timelog : bool, optional

If True, streamer will write its timelog to a file before stopping

wait(sampleStart, sampleEnd, timeout=1, sleep=0.00050000000000000001)[source]

Gets the data from the buffer. Blocks if data is not available and releases if one of the following is true:

  1. data is available
  2. timeout is over
  3. data is overwritten
Parameters :

sampleStart : int

first sample index (included)

sampleEnd : int

last samples index (excluded)

timeout : float, optional

timeout (seconds)

sleep : float, optional

time to wait until the next loop iteration. Used to avoid 100% processor loading.

Returns :

data : ndarray (view or copy) or None

data chunk or None, if the data is overwritten or the timeout has expired

class rdaclient.Streamer(q, fd, raw)[source]

A Streamer class. Inherited from the multiprocessing.Process. It is spawned by a Client to work in the background and receive the data.

The buffer interface is initialized with a provided raw sharedctypes buffer array.

Parameters :

q : Queue

Queue object for interprocess communication

fd : int

socket file descriptor (the one which is connected to a server)

raw : sharectypes char array:

a raw sharedctypes buffer array.

Methods

is_alive() Return whether process is alive
join([timeout]) Wait until child process terminates
run() The main streaming loop.
start() Start child process
terminate() Terminate process; sends SIGTERM signal or uses TerminateProcess()
run()[source]

The main streaming loop.

Previous topic

Tutorial

This Page