June 15, 2015

2015 RingBuffer Library APIs

Contents

A Typical Acquisition Program

An acquisition program using the RingBuffer library must use at least these API calls, in the order shown:





All RingBuffer library APIs, Alphabetical Order

BOOL CLOSE_DRIVER(HANDLE hdevice)

Closes the device being used, either Usb or TCP socket, and releases it for re-use.

Parameters: Returns: Contents

FLOAT GET_BYTES_PER_MSEC(void)

Get the ring buffer fill rate.

Parameters: Returns: Contents

INT GET_CHANNEL_THROUGHPUT(void)

Get the ring buffer channel fill rate.

Parameters: Returns:

This is a measured fill rate. If the buffer is being filled from a Usb, this should be close to the actual rate at which the channel is being sampled. If the buffer is being filled from a socket, the rate is determined using the number of channels being transferred, which may be less than the number being sampled remotely. Ideally the client and server channel fill rates should closely match.

Contents

PCHAR GET_DRIVER_INFO(PCHAR infoBuffer, SIZE_T infoSize)

Get library version number and other run parameters as an ASCII string.

Parameters: Returns

The string returned in "infoBuffer" is NULL terminated.

Contents

PCHAR GET_HARDWARE_PARAMETER(INT which, PCHAR infoBuffer, SIZE_T infoSize)

Get a hardware parameter as an ASCII string.

Parameters: Returns

The string returned in "infoBuffer" is NULL terminated. If the requested parameter is not available, a 0 length string is returned, i.e. infoBuffer[0] = 0.

Contents

INT GET_NUM_CHANNELS_USB(void)

Get the number of channels being sampled.

Parameters: Returns:

This is the size of a single channel sweep in the ring buffer. If this is a client application taking samples from a socket and the client has requested only a subset of samples be transferred, the sweep size still matches that being used by the server. Channels not transferred are set to x'ffffff00'.

Contents

INT GET_NUM_CHANNELS_XFR(void)

Get the number of channels being transferred from a remote acquisition.

Parameters: Returns:

By default, all channels being acquired at the remote Usb are transferred. A reduced number of channels can be requested using the call SET_TRANSFER_CHANNEL_REQUEST_RANGES.

Contents

INT GET_NUM_RESYNCS(void)

Get the number of socket re-syncs (re-connects) that have occurred during this run.

Parameters: Returns:

Re-syncs occur when the socket transmission rate cannot keep up with the Usb acquisition rate. This is usually detected at the serving end and causes the server to close the channel. The client immediately re-connects but some sets of samples are lost to the client. By default, all channels being acquired at the remote Usb are transferred. Reducing the number of channels being transferred should reduce the number of re-syncs. A reduced number of channels can be requested using the call SET_TRANSFER_CHANNEL_REQUEST_RANGES.

Contents

INT GET_REMOTE_CHANNEL_THROUGHPUT(void)

Get the remote ring buffer channel fill rate.

Parameters: Returns:

This fill rate is measured by the remote application. It should be close to the actual rate at which the channel is being sampled.

Contents

INT GET_STRIDE(void)

Get the current STRIDE setting being used.

Parameters: Returns:

STRIDE can be set also using parameters "stride_kb" or "stride_ms" in the "ringbuffer.ini" file or by a call to SET_STRIDE_MS or SET_STRIDE_KB. The default is 131072 bytes.

Contents

BOOL GET_SYNC(void)

Get the current SYNC setting being used.

Parameters: Returns:

When SYNC is TRUE, READ_POINTER and READ_POINTER_WITH_CYCLE expect position values in the parameters "cycleNum" and "pointer" when called and won't return until the position changes; when SYNC is FALSE, these routines return immediately. When the call doesn't return until there is a position change, the caller doesn't loop burning up CPU time. SYNC can be set on/off also by using parameter "sync" or "nosync" in the "ringbuffer.ini" file or by calling SET_SYNC.

Contents

HANDLE OPEN_DRIVER(void)

Initializes the ring buffer support library.

Parameters: Returns:

The ring buffer can be filled with samples from either

The first choice is to use usb input if a BioSemi receiver is connected to this computer via usb and the device is not being used by another program. If usb input is not available, TCP socket input will be attempted. The node and port of a sample server for the TCP connection can be set before this call, otherwise a TCP connection to the current computer will be attempted.

The parameter file "ringbuffer.ini" is read during the first OPEN_DRIVER call only. Parameters set by API calls before that first OPEN are overridden by any corresponding parameters in the file; parameters set after that first OPEN will override anything set by the file.

Contents

BOOL READ_MULTIPLE_SWEEPS(HANDLE hdevice,PCHAR data,INT_PTR nBytesToRead)

Creates a thread to control the acquisition process.

Parameters: Returns:

Establishes the ring buffer to be used to receive samples during data acquisition. Starts a separate thread to control the acquisition process. The actual flow of samples doesn't start until enabled by a call to USB_WRITE.

The ring buffer can be any size as long as it is a multiple of 512 bytes (Linux and OSX) or a multiple of 4 bytes (Windows).

Because the ring buffer may be undergoing transmission to a remote client via Tcp, the contents of this buffer should not be changed by the user during acquisition.

Contents

BOOL READ_POINTER(HANDLE hdevice,PINT_PTR pointer)

Determines the position in the ring buffer (a byte index) at which new samples are being stored.

Parameters: Returns:

When the ring buffer is being filled from a socket rather than the Usb, a single FALSE return indicates that a re-sync has occurred; two FALSE returns in a row indicate that acquisition has stopped.

Note: When using sync'ed READ_POINTER calls, "pointer" is an input and output parameter.

Contents

BOOL READ_POINTER_WITH_CYCLE(HANDLE hdevice,long long *cycleNum,PINT_PTR pointer)

Determines the cycle and position in the ring buffer (a byte index) at which new samples are being stored.

Parameters: Returns:

Together "cycleNum" and "pointer" can be used to determine if data overrun has occurred in the ring buffer since the last call. Data overrun is when a complete cycle of the buffer has occurred since the last call. For example, it would be overrun if:

When the ring buffer is being filled from a socket rather than the Usb, a single FALSE return indicates that a re-sync has occurred; two FALSE returns in a row indicate that acquisition has stopped.

Note: When using sync'ed READ_POINTER calls, both "cycleNum" and "pointer" are input and output parameters.

Contents

VOID SET_CONNECT_NODE_PORT(const char *node, const char *port)

Set the node and port to connect to if running in client mode.

Parameters: Returns:

The connect node can be set also using parameter "connect_node" in the "ringbuffer.ini" file. The default is the loopback address, "127.0.0.1".

The connect port can be set also using parameter "connect_port" in the "ringbuffer.ini" file. The default is the "3113".

Setting the connect port to "0" disables any connection attempt.

Contents

VOID SET_LISTEN_PORT(const char *port)

Set the port to listen to if running in sample server mode.

Parameters: Returns:

The listen port can be set also using parameter "listen_port" in the "ringbuffer.ini" file. The default is the "3113".

Setting the listen port to "0" disables listening for client connection attempts.

Contents

VOID SET_STRIDE_KB(int kBytes)

Set the STRIDE to be used.

Parameters: Returns:

STRIDE can be set also using parameters "stride_kb" or "stride_ms" in the "ringbuffer.ini" file or by a call to SET_STRIDE_MS. The default is 131072 bytes.

Contents

VOID SET_STRIDE_MS(int msec)

Set the STRIDE to be used.

Parameters: Returns:

STRIDE can be set also using parameters "stride_ms" or "stride_kb" in the "ringbuffer.ini" file or by a call to SET_STRIDE_KB. The default is 131072 bytes.

Contents

VOID SET_SYNC(BOOL onOff)

Set the SYNC value to be used.

Parameters: Returns:

When SYNC is TRUE, READ_POINTER and READ_POINTER_WITH_CYCLE expect position values in the parameters "cycleNum" and "pointer" when called and won't return until the position changes; when SYNC is FALSE, these routines return immediately. When the call doesn't return until there is a position change, the caller doesn't loop burning up CPU time.

SYNC can be set on/off also by using parameters "sync" or "nosync" in the "ringbuffer.ini" file.

Contents

BOOL SET_TRANSFER_CHANNEL_REQUEST_RANGES(int numRanges, int *channelRanges)

Set the channels to be transferred by socket from the Usb ring buffer.

Parameters: Returns:

When the ring buffer is being filled from a socket, channels not transferred are set to x'ffffff00'.

Contents

BOOL USB_WRITE(HANDLE hdevice, PCHAR data)

Write a 64 byte array to the BioSemi Usb Receiver.

Parameters: Returns:

The byte array "data" is used to start and stop the flow of samples through the Usb interface and to send trigger outputs:

Contents

BOOL DOWNLOAD_FX2_EEPROM(void)

Download an FX2 EEPROM file using Usb.

Parameters: Returns:

The file to be downloaded must be called "USB2.iic". It is expected to exist in:

Contents

BOOL DOWNLOAD_FX2_IIC_FIRMWARE(void)

Download an FX2 IIC Firmware file using Usb.

Parameters: Returns:

The file to be downloaded must be called "Vend_Ax.bix". It is expected to exist in:

Contents












INT GET_REMOTE_ERRORCODE(void)