This labscript device is a master device that can control a wide range of NI Multi-function data acquistion devices.


This labscript device requires an installation of the NI-DAQmx module, available for free from NI.

The python bindings are provided by the PyDAQmx package, available through pip.

Adding a Device

While the NI_DAQmx device can be used directly by manually specifying the many necessary parameters, it is preferable to add the device via an appropriate subclass. This process is greatly simplified by using the script followed by the script.

To add support for a DAQmx device that is not yet supported, run on a computer with the device in question connected (or with a simulated device of the correct model configured in NI-MAX). This will introspect the capabilities of the device and add those details to capabilities.json. To generate labscript device classes for all devices whose capabilities are known, run Subclasses of NI_DAQmx will be made in the models subfolder, and they can then be imported into labscript code with:

from labscript_devices.NI_DAQmx.labscript_devices import NI_PCIe_6363

or similar. The class naming is based on the model name by prepending “NI_” and replacing the hyphen with an underscore, i.e. ‘PCIe-6363’ -> NI_PCIe_6363.

Generating device classes requires the Python code-formatting library ‘black’, which can be installed via pip (Python 3.6+ only). If you don’t want to install this library, the generation code will still work, it just won’t be formatted well.

The current list of pre-subclassed devices is:


NI Multifunction DAQs generally provide hardware channels for StaticAnalogOut, StaticDigitalOut, AnalogOut, DigitalOut, and AnalogIn labscript quantities for use in experiments. Exact numbers of channels, performance, and configuration depend on the model of DAQ used.

from labscript import *

from labscript_devices.DummyPseudoclock.labscript_devices import DummyPseudoclock
from labscript_devices.NI_DAQmx.models.NI_USB_6343 import NI_USB_6343





NI DAQs are also used within labscript to provide a WaitMonitor. When configured, the WaitMonitor allows for arbitrary-length pauses in experiment execution, waiting for some trigger to restart. The monitor provides a measurement of the duration of the wait for use in interpreting the resulting data from the experiment.

Configuration uses three digital I/O connections on the DAQ:

  • The parent_connection which sends pulses at the beginning of the experiment, the start of the wait, and the end of the wait.

  • The acquisition_connection which must be wired to a counter and measures the time between the pulses of the parent connection.

  • The timeout_connection which can send a restart pulse if the wait times out.

An example configuration of a WaitMonitor using a NI DAQ is shown here

# A wait monitor for AC-line triggering
# This requires custom hardware
                        acquisition_device=daq, acquisition_connection='ctr0',
                        timeout_device=daq, timeout_connection='PFI1')
# Necessary to ensure even number of digital out lines in shot

Note that the counter connection is specified using the logical label 'ctr0'. On many NI DAQs, the physical connection to this counter is PFI9. The physical wiring for this configuration would have port0/line0 wired directly to PFI9, with PFI1 being sent to the master pseudoclock retriggering system in case of timeout. If timeouts are not expected/represent experiment failure, this physical connection can be omitted.

Detailed Documentation

class labscript_devices.NI_DAQmx.labscript_devices.NI_DAQmx(name, parent_device=None, clock_terminal=None, MAX_name=None, static_AO=None, static_DO=None, clock_mirror_terminal=None, acquisition_rate=None, AI_range=None, AI_range_Diff=None, AI_start_delay=0, AI_start_delay_ticks=None, AI_term='RSE', AI_term_cfg=None, AO_range=None, max_AI_multi_chan_rate=None, max_AI_single_chan_rate=None, max_AO_sample_rate=None, max_DO_sample_rate=None, min_semiperiod_measurement=None, num_AI=0, num_AO=0, num_CI=0, ports=None, supports_buffered_AO=False, supports_buffered_DO=False, supports_semiperiod_measurement=False, supports_simultaneous_AI_sampling=False, **kwargs)[source]

Bases: labscript.labscript.IntermediateDevice

Generic class for NI_DAQmx devices.

Generally over-ridden by device-specific subclasses that contain the introspected default values.

  • name (str) – name to assign to the created labscript device

  • parent_device (clockline) – Parent clockline device that will clock the outputs of this device

  • clock_terminal (str) – What input on the DAQ is used for the clockline

  • MAX_name (str) – NI-MAX device name

  • static_AO (int, optional) – Number of static analog output channels.

  • static_DO (int, optional) – Number of static digital output channels.

  • clock_mirror_terminal (str, optional) – Channel string of digital output that mirrors the input clock. Useful for daisy-chaning DAQs on the same clockline.

  • acquisiton_rate (float, optional) – Default sample rate of inputs.

  • AI_range (iterable, optional) – A [Vmin, Vmax] pair that sets the analog input voltage range for all analog inputs.

  • AI_range_Diff (iterable, optional) – A [Vmin, Vmax] pair that sets the analog input voltage range for all analog inputs when using Differential termination.

  • AI_start_delay (float, optional) – Time in seconds between start of an analog input task starting and the first sample.

  • AI_start_delay_ticks (int, optional) – Time in sample clock periods between start of an analog input task starting and the first sample. To use this method, AI_start_delay must be set to None. This is necessary for DAQs that employ delta ADCs.

  • AI_term (str, optional) – Configures the analog input termination for all analog inputs. Must be supported by the device. Supported options are 'RSE', 'NRSE' 'Diff', and ‘PseudoDiff'.

  • AI_term_cfg (dict, optional) – Dictionary of analog input channels and their supported terminations. Best to use to introspect these.

  • AO_range (iterable, optional) – A [Vmin, Vmax] pair that sets the analog output voltage range for all analog outputs.

  • max_AI_multi_chan_rate (float, optional) – Max supported analog input sampling rate when using multiple channels.

  • max_AI_single_chan_rate (float, optional) – Max supported analog input sampling rate when only using a single channel.

  • max_AO_sample_rate (float, optional) – Max supported analog output sample rate.

  • max_DO_sample_rate (float, optional) – Max supported digital output sample rate.

  • min_sermiperiod_measurement (float, optional) – Minimum measurable time for a semiperiod measurement.

  • num_AI (int, optional) – Number of analog inputs channels.

  • num_AO (int, optional) – Number of analog output channels.

  • num_CI (int, optional) – Number of counter input channels.

  • ports (dict, optional) – Dictionarly of DIO ports, which number of lines and whether port supports buffered output.

  • supports_buffered_AO (bool, optional) – True if analog outputs support buffered output

  • supports_buffered_DO (bool, optional) – True if digital outputs support buffered output

  • supports_semiperiod_measurement (bool, optional) – True if device supports semi-period measurements


Check that analog input acquisition rates do not exceed maximums.


Check that all analog outputs are in bounds

_check_even_children(analogs, digitals)[source]

Check that there are an even number of children of each type.


Check that if we are the wait monitor acquisition device and another device is the wait monitor timeout device, that a) the other device is a DAQmx device and b) the other device has a start_order lower than us and a stop_order higher than us.


Collect analog input instructions and create the acquisition table

_make_analog_out_table(analogs, times)[source]

Collect analog output data and create the output array

_make_digital_out_table(digitals, times)[source]

Collect digital output data and create the output array


Error checking for adding a child device.


device (labscript device) – Child labscript device to attach to this device. Only types of devices in allowed_children can be attached.

allowed_children = []

Sets the allowed children types based on the capabilites.

description = 'NI-DAQmx'

Generates the hardware code from the script and saves it to the shot h5 file.

This is called automatically when a shot is compiled.


hdf5_file (str) – Path to shot’s hdf5 file to save the instructions to.

wait_monitor_supports_wait_completed_events = True

Return the smallest unsigned integer type sufficient to contain n bits

class labscript_devices.NI_DAQmx.blacs_tabs.NI_DAQmxTab(notebook, settings, restart=False)[source]

Bases: blacs.device_base_class.DeviceTab

class labscript_devices.NI_DAQmx.blacs_workers.NI_DAQmxAcquisitionWorker(*args, **kwargs)[source]

Bases: blacs.tab_base_classes.Worker

MAX_READ_PTS = 10000
extract_measurements(raw_data, waits_in_use)[source]
read(task_handle, event_type, num_samples, callback_data=None)[source]

Called as a callback by DAQmx while task is running. Also called by us to get remaining data just prior to stopping the task. Since the callback runs in a separate thread, we need to serialise access to instance variables

start_task(chans, rate)[source]

Set up a task that acquires data with a callback every MAX_READ_PTS points or MAX_READ_INTERVAL seconds, whichever is faster. NI DAQmx calls callbacks in a separate thread, so this method returns, but data acquisition continues until stop_task() is called. Data is appended to self.acquired_data if self.buffered_mode=True, or (TODO) sent to the [whatever the AI server broker is called] if self.buffered_mode=False.

transition_to_buffered(device_name, h5file, initial_values, fresh)[source]
class labscript_devices.NI_DAQmx.blacs_workers.NI_DAQmxOutputWorker(*args, **kwargs)[source]

Bases: blacs.tab_base_classes.Worker


Check the version of PyDAQmx is high enough to avoid a known bug

get_output_tables(h5file, device_name)[source]

Return the AO and DO tables rom the file, or None if they do not exist.


Create the DO task and program in the DO table for a shot. Return a dictionary of the final values of each channel in use


Mirror the clock terminal on another terminal to allow daisy chaining of the clock line to other devices, if applicable

transition_to_buffered(device_name, h5file, initial_values, fresh)[source]
class labscript_devices.NI_DAQmx.blacs_workers.NI_DAQmxWaitMonitorWorker(*args, **kwargs)[source]

Bases: blacs.tab_base_classes.Worker

read_edges(npts, timeout=None)[source]

Wait up to the given timeout in seconds for an edge on the wait monitor and and return the duration since the previous edge. Return None upon timeout.

transition_to_buffered(device_name, h5file, initial_values, fresh)[source]
class labscript_devices.NI_DAQmx.runviewer_parsers.NI_DAQmxParser(path, device)[source]

Bases: object

get_traces(add_trace, clock=None)[source]

Introspect whether a device has ‘incomplete sample detection’, described here:

The result is determined empirically by outputting a pulse on one counter and measuring it on another, and seeing whether the first sample was discarded or not. This requires a non-simulated device with at least two counters. No external signal is actually generated by the device whilst this test is performed. Credit for this method goes to Kevin Price, who provided it here:

This workaround will hopefully be deprecated if and when NI provides functionality to either inspect this feature’s presence directly, or to disable it regardless of its presence.


Return analog input number of a connection string such as ‘ai1’ as an integer, or raise ValueError if format is invalid


Return analog output number of a connection string such as ‘ao1’ as an integer, or raise ValueError if format is invalid


Return the port and line number of a connection string such as ‘port0/line1 as two integers, or raise ValueError if format is invalid. Accepts connection strings such as port1/line0 (PFI0) - the PFI bit is just ignored


Return PFI input number of a connection string such as ‘PFI0’ as an integer, or raise ValueError if format is invalid


Return port number of a string such as ‘port0’ as an integer, or raise ValueError if format is invalid