C++ API#

General structures#

enum class maxlab::FilterType : int#

Enum that represents the possible types of filters that can be selected.

Values:

enumerator FIR#

Default filter, higher latency.

enumerator IIR#

Lower latency filter.

struct FrameInfo#

Information about the state of a data frame.

In particular, the frame-number, the well-id and if the frame is corrupted or not.

Public Functions

inline constexpr FrameInfo()#

Default constructor, initializes all members to zero/false.

inline constexpr FrameInfo(uint64_t f, uint8_t w, bool c)#

Constructs a FrameInfo with specific values.

Parameters:
  • f – Frame number.

  • w – Well Id.

  • c – Corrupted flag.

inline explicit FrameInfo(const maxlab_FrameInfo *c_info)#

Explicitly constructs a FrameInfo from the C structure maxlab_FrameInfo.

Construct from opaque C pointer using accessors.

Parameters:

c – The C structure to copy from.

Public Members

uint64_t frame_number#

Frame number.

uint8_t well_id#

Well Id on MultiWell devices.

bool corrupted#

If frame is corrupted or not. If corrupted, no guarantees on data contained in it.

inline Status maxlab::sendSequence(const char *sequenceName)#

Function to trigger sending of sequence from mxwserver to the device.

Parameters:

sequenceName – The name of the predefined maxlab.sequence.Sequence with the Python API.

Returns:

Status of the API call.

enum class maxlab::Status : int#

Enum indicating all possible error codes.

Values:

enumerator MAXLAB_OK#

The operation completed successfully.

enumerator MAXLAB_API_FAIL#

The API call failed for an unspecified reason.

enumerator MAXLAB_NO_SERVER_CONNECTION#

No connection to the server could be established.

enumerator MAXLAB_LICENSE_INVALID#

The required license is invalid.

enumerator MAXLAB_API_NO_RESPONSE#

The API call did not receive a response from the server.

enumerator MAXLAB_STREAM_ALREADY_OPENED#

An attempt was made to open an already open stream.

enumerator MAXLAB_INCOMPATIBLE_FILTERING#

The specified filter configuration is incompatible.

enumerator MAXLAB_INVALID_INPUT#

The input provided to the function was invalid.

enumerator MAXLAB_STREAM_NOT_OPENED#

An operation on a stream was attempted but the stream is not open.

enumerator MAXLAB_NO_FRAME#

No data frame was available to be received.

inline void maxlab::verifyStatus(Status status)#

Function to verify that status is maxlab::Status::MAXLAB_OK.

This function checks if status is ok and otherwise prints the error message to stdcerr and exits the execution with error code 1.

Parameters:

status –

struct maxlab::SpikeEvent#

Structure used for encoding of a spike occurrence. This structure stores the frame number at which a spike is detected (typically at the maximal value of the spike), the amplitude of that spike, and the channel at which this spike was detected.

unsigned long frameNo#

The frame number of the spike event.

float amp#

Amplitude of the spike.

uint16_t channel#

The channel on which the spike was recorded.

unsigned char wellId#

The well ID where the spike was observed.

struct FilteredFrameData#

Structure to store the information obtained from the filtered data stream.

The filtered data stream contains all detected spikes at each individual frame.

Note that there will at most be a 1024 spikes (i.e. the number of readout channels), but there might be less. You thus need to make sure to never access memory that is further offset from the spikeEvents pointer than spikeCount.

Example

maxlab::FilteredFrameData frame;
maxlab::DataStreamerFiltered_receiveNextFrame(&frame);
frame.spikeEvents[frame.spikeCount - 1]    // Valid access if there is at least one spike
frame.spikeEvents[frame.spikeCount]        // Invalid access and undefined behaviour

Public Functions

inline constexpr FilteredFrameData()#

Default constructor.

inline explicit FilteredFrameData(const maxlab_FilteredFrameData *c_data)#

Explicitly constructs a FilteredFrameData from the C structure maxlab_FilteredFrameData.

Parameters:

c_data – The C structure to copy from.

Public Members

uint64_t spikeCount#

How many spikes were detected, i.e., the length of the spikeEvents array.

const SpikeEvent *spikeEvents#

Pointer to spikes.

FrameInfo frameInfo#

Information about the current frame even if no spikes were detected.

struct RawFrameData#

Structure to store the information obtained from the raw data stream.

Note that there are always exactly 1024 amplitudes (i.e. the number of readout channels).

Example

frame->amplitudes[frame->amplitudeCount - 1]    // Valid access
frame->amplitudes[frame->amplitudeCount]        // Invalid access and undefined behaviour

Public Functions

inline constexpr RawFrameData()#

Default constructor.

inline explicit RawFrameData(const maxlab_RawFrameData *c_data)#

Explicitly constructs a RawFrameData from the C structure maxlab_RawFrameData.

Parameters:

c_data – The C structure to copy from.

Public Members

FrameInfo frameInfo#

For more infos see maxlab::FrameInfo.

uint64_t amplitudeCount#

Fixed size of the amplitudes pointer (always 1024).

const float *amplitudes#

Pointer to the array of amplitudes.

Filtered data#

inline Status maxlab::DataStreamerFiltered_open(FilterType filterType)#

Creates the connection to the filtered data stream.

It is recommended to use maxlab::verifyStatus to check the return of this function.

Warning

As soon as the stream is open, all incoming frames are buffered in memory until they are retrieved with maxlab::DataStreamerFiltered_receiveNextFrame. See that function for details.

Parameters:

filterType – Specify the type of filtering you want. For more information, see maxlab::FilterType.

Returns:

Status of the initialization of the stream. Possible values are:

  • maxlab::Status::MAXLAB_OK

  • maxlab::Status::MAXLAB_LICENSE_INVALID

  • maxlab::Status::MAXLAB_STREAM_ALREADY_OPENED

  • maxlab::Status::MAXLAB_INCOMPATIBLE_FILTERING

  • maxlab::Status::MAXLAB_NO_SERVER_CONNECTION

inline Status maxlab::DataStreamerFiltered_close()#

Closes the connection to the filtered data stream and restores the state of the mxwserver to the default.

Note that you should ensure to always call this function at the end of your experiment and check with maxlab::verifyStatus if the closing worked correctly. If it did not, make sure to restart mxwserver before starting any new runs or doing experiments in scope.

Returns:

Status of the closure of the stream. Possible values are:

  • maxlab::Status::MAXLAB_OK

  • maxlab::Status::MAXLAB_NO_SERVER_CONNECTION

  • maxlab::Status::MAXLAB_API_NO_RESPONSE

inline Status maxlab::DataStreamerFiltered_receiveNextFrame(FilteredFrameData *frameData)#

Receive next frame from filtered data stream if there is one.

This function is currently blocking, i.e. it waits to receive data for 1 millisecond, if it takes longer we return maxlab::Status::MAXLAB_NO_FRAME, otherwise maxlab::Status::MAXLAB_OK.

If you receive maxlab::Status::MAXLAB_NO_FRAME it means that something is wrong (dropped frames, corrupted frames, etc.).

Frame buffering

While the stream is open, every frame sent by the system is queued internally until it is retrieved with this function. Frames are returned in order (first in, first out), so each call returns the oldest frame not yet received, not the most recent one. For example, if you call this function at t = 10 s and next call it at t = 15 s, the second call returns the frame that directly follows the one received at t = 10 s. The ~5 s of frames in between are still in the queue and will be returned by the following calls. You can use frameInfo.frame_number to check which frame you received.

In closed-loop applications, keep in mind that any backlog in the queue adds latency: the frames you receive are older than the current state of the system until the queue has been emptied.

Warning

The internal queue has no size limit and does not overflow or drop old frames. No error is reported either. If frames are not retrieved at least as fast as the system produces them, the queue keeps growing until the available physical memory is used up, and the operating system then terminates the process. This also applies to pauses in your experiment. To avoid it, either:

  • keep calling this function while the stream is open and discard the frames you do not need, or

  • close the stream with maxlab::DataStreamerFiltered_close during longer pauses and reopen it afterwards.

Parameters:

frameData – Buffer in which data can be written into.

Returns:

Status of the receiving operation. Possible values are:

  • maxlab::Status::MAXLAB_OK

  • maxlab::Status::MAXLAB_INVALID_INPUT

  • maxlab::Status::MAXLAB_STREAM_NOT_OPENED

  • maxlab::Status::MAXLAB_NO_FRAME

inline Status maxlab::DataStreamerFiltered_setFilterType(FilterType filterType)#

Allows the change of filter-type while keeping the data stream open.

Parameters:

filterType – Filter type, for more information see maxlab::FilterType.

Returns:

Status of the operation. Possible values are:

  • maxlab::Status::MAXLAB_OK

  • maxlab::Status::MAXLAB_STREAM_NOT_OPENED

  • maxlab::Status::MAXLAB_INCOMPATIBLE_FILTERING

inline FilterType maxlab::DataStreamerFiltered_getFilterType()#

Get currently set filter type.

Returns:

Filter type, for more infos, see maxlab::FilterType.

Raw data#

inline Status maxlab::DataStreamerRaw_open()#

Creates the connection to the raw data stream.

It is recommended to use maxlab::verifyStatus to check the return of this function.

Warning

As soon as the stream is open, all incoming frames are buffered in memory until they are retrieved with maxlab::DataStreamerRaw_receiveNextFrame. See that function for details.

Returns:

Status of the initialization of the stream. Possible values are:

  • maxlab::Status::MAXLAB_OK

  • maxlab::Status::MAXLAB_LICENSE_INVALID

  • maxlab::Status::MAXLAB_STREAM_ALREADY_OPENED

  • maxlab::Status::MAXLAB_INCOMPATIBLE_FILTERING

  • maxlab::Status::MAXLAB_NO_SERVER_CONNECTION

inline Status maxlab::DataStreamerRaw_close()#

Closes the connection to the raw data stream and discards all frames that are still buffered.

Note that you should ensure to always call this function at the end of your experiment.

Returns:

Status of the closure of the stream. Always maxlab::Status::MAXLAB_OK.

inline Status maxlab::DataStreamerRaw_receiveNextFrame(RawFrameData *frameData)#

Receive next frame from raw data stream if there is one.

This function is currently blocking, i.e. it waits to receive data for 1 millisecond, if it takes longer we return maxlab::Status::MAXLAB_NO_FRAME, otherwise maxlab::Status::MAXLAB_OK.

If you receive maxlab::Status::MAXLAB_NO_FRAME it means that something is wrong (dropped frames, corrupted frames, etc.).

Frame buffering

While the stream is open, every frame sent by the system is queued internally until it is retrieved with this function. Frames are returned in order (first in, first out), so each call returns the oldest frame not yet received, not the most recent one. For example, if you call this function at t = 10 s and next call it at t = 15 s, the second call returns the frame that directly follows the one received at t = 10 s. The ~5 s of frames in between are still in the queue and will be returned by the following calls. You can use frameInfo.frame_number to check which frame you received.

In closed-loop applications, keep in mind that any backlog in the queue adds latency: the frames you receive are older than the current state of the system until the queue has been emptied.

Warning

The internal queue has no size limit and does not overflow or drop old frames. No error is reported either. If frames are not retrieved at least as fast as the system produces them, the queue keeps growing until the available physical memory is used up, and the operating system then terminates the process. This also applies to pauses in your experiment. To avoid it, either:

  • keep calling this function while the stream is open and discard the frames you do not need, or

  • close the stream with maxlab::DataStreamerRaw_close during longer pauses and reopen it afterwards.

Parameters:

frameData – Buffer in which data can be written into.

Returns:

Status of the receiving operation. Possible values are:

  • maxlab::Status::MAXLAB_OK

  • maxlab::Status::MAXLAB_INVALID_INPUT

  • maxlab::Status::MAXLAB_STREAM_NOT_OPENED

  • maxlab::Status::MAXLAB_NO_FRAME