Table of Contents

ContextTask

Encapsulates a single ONI context and orchestrates interaction with ONI-compliant hardware.

The Open Neuro Interface (ONI) hardware specification and API describe a general purpose acquisition system architecture and programming interface for communication with a host PC. One requirement of ONI is that a host application must hold a "context" that contains handles for hardware communication, data acquisition parameters, etc. for a particular hardware controller, such as the ONIX PCIe card. ContextTask fulfills this role for this library. Additionally, once data acquisition is started by the StartAcquisition operator, ContextTask performs the following:

  • It automatically reads and distributes data from hardware using a dedicated acquisition thread.
  • It allows data to be written to devices that accept them.
  • It allows reading from and writing to device registers to control their operation (e.g. Enable or AnalogHighCutoff).
Additionally, this operator exposes important information about the underlying ONI hardware such as the device table, clock rates, and block read and write sizes. In summary, ContextTask forms a complete interface for all hardware interaction within the library: all physical interaction with the ONIX system passes through this class.

Properties

Property Type Description
AcquisitionClockHz uint

Gets the acquisition clock rate in Hz.

This property describes the frequency of ONI controller's acquisition clock, which is used to generate the Clock counter value included in all data frames produced by Data IO operators in this library (e.g. NeuropixelsV1eData or Bno055Data). The value of this property is determined during hardware initialization.

BlockReadSize int

Gets the number of bytes read per cycle of the ContextTask's acquisition thread.

This option allows control over a fundamental trade-off between closed-loop response time and available bandwidth. A minimal value, which is determined by MaxReadFrameSize, will provide the lowest response latency, so long as data can be cleared from hardware memory fast enough to prevent buffering. Larger values will both reduce system call frequency and reduce the number of function calls per unit time performed by Bonsai, and therefore, increase available bandwidth. Larger values may improve processing performance for high-bandwidth data sources. The optimal value depends on the host computer and hardware configuration and must be determined via testing (e.g. using MemoryMonitorData).

BlockWriteSize int

Gets the number of bytes that are pre-allocated for writing data to hardware.

This value determines the amount of memory that is pre-allocated for calls to Write(uint, IntPtr, int), Write<T>(uint, T), and Write<T>(uint, T[]). A larger size will reduce the frequency of dynamic memory allocation system calls but increase the expense of each of those calls. The minimum size of this option is determined by MaxWriteFrameSize. The effect on real-time performance is typically not as large as that of BlockReadSize because this parameter defines a readily-available pool of memory for the creation of output data frames, but does not determine when they are written to hardware. Data is written to hardware as soon as an output frame has been created. In contrast data is read from hardware whenever more than ReadSize bytes have accumulated in the input buffer.

DeviceTable Dictionary<uint, Device>

Gets the device table containing the device hierarchy of the acquisition system.

This dictionary provides access to the ONI Device Table, which maps a set of fully-qualified ONI Device Addresses to a corresponding set of ONI Device Descriptors. The value of this property is determined during hardware initialization.

MaxReadFrameSize uint

Gets the size of the largest data frame produced by any device with the acquisition system in bytes.

This number describes the the size, in bytes, of the largest ONI Data Frame produced by any device within the current device table that generates data. Therefore, it also defines the lower bound for the value of BlockReadSize. The value of this property is determined during hardware initialization.

MaxWriteFrameSize uint

Gets the size of the largest data frame consumed by any device with the acquisition system in bytes.

This number describes the the size, in bytes, of the largest ONI Data Frame consumed by any device within the current device table that accepts data. Therefore, it also defines the lower bound for the value of BlockWriteSize. The value of this property is determined during hardware initialization.

SystemClockHz uint

Gets the system clock rate in Hz.

This property describes the frequency of the clock governing the ONI controller. The value of this property is determined during hardware initialization.