Expand description

Struct and methods corresponding to NI-hardware channels. See BaseChannel for implementation details.

Channels constitute the fundamental unit of interaction with NI devices, and between NI devices and controlled hardware. A Channel instance, trivially implementing the BaseChannel trait, corresponds to a physical channel on a NI device and, by extension, a controllable physical quantity (e.g. laser on/off, coil current).

Editing behavior

During editing, the user effectively adds InstrBook instances (instructions with associated intervals) into the instr_list field through wrapper methods. The instr_list field functions as an edit cache and maintains a sorted list of newly added instruction books.

Compilation behavior

Compilation is analogous to “flushing” the edit cache of an experiment. During compilation, instructions within the edit cache via instr_list — which could be disjointed — are expanded according to their keep_val property and combined to produce a continuous stream of Instruction, which is stored in instr_end and instr_val.

Properties of a channel include:

  • samp_rate: The sampling rate at which the parent device operates.
  • name: Denotes the channel’s identifier as seen by the NI driver. For instance, this could be ‘ao0’ or ‘port0/line0’. This name can be viewed using tools like NI-MAX on Windows or the NI hardware configuration utilities on Linux.
  • instr_list: An edit-cache for the channel. Internally, this uses a BTreeSet to guarantee the sorted ordering of non-overlapping instruction intervals.
  • task_type: Specifies the task type associated with the channel. This affects the behavior of certain methods within the channel.
  • fresh_compiled: An internal boolean value that indicates whether the compiled results (stored in instr_end and instr_val) are up-to-date with the content of the edit cache.

Channel property: “editable” and “streamable”

For AO (Analog Output) channels, each edited channel corresponds directly to a NI-DAQmx channel. However, the situation becomes nuanced when we consider DO (Digital Output) channels. In DAQmx, digital channels can be of type “line” or “port”.

A single port can encompass anywhere from 8 to 32 lines. Importantly, each of these lines can produce an arbitrary output. In this library, the unit of independent digital triggers, which users interact with, corresponds to DAQmx “lines”. These lines accept boolean values for individual writes.

However, DAQmx offers a more efficient mechanism: writing integers to “ports”. In this method, each significant binary bit in the sequence corresponds to a line’s output. This port-based approach provides a substantial efficiency gain, making it indispensable for successful digital output streaming.

As a result, while library users interact with “line channels” (with names in the format like "port0/line0"), the library internally aggregates lines from the same port during compilation. This aggregation merges their instructions for streamlined execution.

For instance, if line0/port0 is high between t=1~3 and line0/port4 is high between t=2~4, the parent device compilation will produce an auxiliary port channel named port0. This channel has compiled instructions as follows: (0, t=0~1), (1, t=1~2), (17, t=2~3), (16, t=3~4), (0, t=4~5).

Channels generated in this manner are labeled as streamable, meaning directly used during experiment streaming to generate driver-write signals. Channels which users directly interact with are labeled as editable.

AO channels are both streamable and editable. DO line channels are editable but not streamable, and DO port channels are non-editable yet streamable.

Structs

  • Represents a physical channel on an NI device.

Enums

  • Enum type for NI tasks. Channels are associated with a unique task type, which affects their behavior. Currently supported types: AO (analogue output), DO (digital output)

Traits

  • The BaseChannel trait defines the core methods required for a channel’s interaction with NI devices. It encapsulates both editing and compilation behaviors of a channel.