Reference

Public API to describe and run NI-DAQmx tasks from any Python code.

It never imports Qt nor the PyMoDAQ GUI. See the documentation for the stability promise.

System

class pymodaq_plugins_daqmx.hardware.national_instruments.api.NIDAQSystem[source]

Bases: object

A view of the NI hardware, read from the driver once and kept until refresh().

Without the NI-DAQmx driver there is simply no device. Everything returned is made of plain strings, numbers and tuples. A device or a kind of channel that does not exist is a ValueError; a property the device does not have (for instance the maximum rate of the analog outputs of a card without any) is None or an empty list.

__init__()[source]
ai_max_rate(device, multi_channel=True)[source]

Maximum sampling rate (Hz) of the analog inputs, for several channels or for a single one.

ai_measurement_types(device)[source]

Kinds of measure of the analog inputs, as lower case names (voltage, temperature_rtd…).

ai_voltage_ranges(device)[source]

Voltage ranges of the analog inputs as (min, max) pairs.

all_channels(kind: ChannelKind) → List[str][source]

Names of the channels of the given kind on all the devices, device after device.

ao_max_rate(device)[source]

Maximum update rate (Hz) of the analog outputs; None if the device has none.

ao_voltage_ranges(device)[source]

Voltage ranges of the analog outputs as (min, max) pairs.

channels(device: str, kind: ChannelKind) → List[str][source]

Names of the channels of device (such as 'Dev1') of the given kind (a ChannelKind or its value: ai, ao, ci, co, di (lines) or do (lines)).

devices()[source]

Names of the devices, such as ['Dev1', 'Dev2']; empty without driver.

refresh()[source]

Forget what was read: the next call asks the driver again (a card may have been plugged in).

supports_start_trigger(device, kind)[source]

Whether a kind (ChannelKind.AI or ChannelKind.DI) task on device can wait for a start trigger.

terminals(device)[source]

Terminals of device (/Dev1/PFI0…), usable as clock or trigger sources.

Tasks

class pymodaq_plugins_daqmx.hardware.national_instruments.api.TaskConfig(channels: Tuple[pymodaq_plugins_daqmx.hardware.national_instruments.api.channels.AIVoltage | pymodaq_plugins_daqmx.hardware.national_instruments.api.channels.AICurrent | pymodaq_plugins_daqmx.hardware.national_instruments.api.channels.AIThermocouple | pymodaq_plugins_daqmx.hardware.national_instruments.api.channels.AIRtd | pymodaq_plugins_daqmx.hardware.national_instruments.api.channels.AOVoltage | pymodaq_plugins_daqmx.hardware.national_instruments.api.channels.AOCurrent | pymodaq_plugins_daqmx.hardware.national_instruments.api.channels.CICountEdges | pymodaq_plugins_daqmx.hardware.national_instruments.api.channels.COPulseFreq | pymodaq_plugins_daqmx.hardware.national_instruments.api.channels.DigitalIn | pymodaq_plugins_daqmx.hardware.national_instruments.api.channels.DigitalOut, ...], timing: pymodaq_plugins_daqmx.hardware.national_instruments.api.timing.ClockSettings | pymodaq_plugins_daqmx.hardware.national_instruments.api.timing.ImplicitTiming | pymodaq_plugins_daqmx.hardware.national_instruments.api.timing.ChangeDetectionSettings | None = None, trigger: pymodaq_plugins_daqmx.hardware.national_instruments.api.triggers.DigitalEdgeTrigger | pymodaq_plugins_daqmx.hardware.national_instruments.api.triggers.AnalogEdgeTrigger | None = None)[source]

Bases: object

__init__(channels: Tuple[AIVoltage | AICurrent | AIThermocouple | AIRtd | AOVoltage | AOCurrent | CICountEdges | COPulseFreq | DigitalIn | DigitalOut, ...], timing: ClockSettings | ImplicitTiming | ChangeDetectionSettings | None = None, trigger: DigitalEdgeTrigger | AnalogEdgeTrigger | None = None) → None
class pymodaq_plugins_daqmx.hardware.national_instruments.api.AnalogInputTask(config: TaskConfig)[source]

Bases: _Task

read_analog(timeout: float | None = None) → ndarray[source]

Read the configured number of samples as a float64 array shaped (channels, samples).

timeout (s) is how long to wait for the samples: by default the duration of the acquisition plus 5 s.

class pymodaq_plugins_daqmx.hardware.national_instruments.api.TaskListener[source]

Bases: object

What a task can tell: derive from it and register the object with task.add_listener.

Both methods are called from driver threads, never from the thread that started the task, one thread per call and without any order between them. Do only what is thread-safe here, or hand the event over to the thread that should handle it (see QtTaskBridge).

on_done(status: int)[source]

The task is done. status is 0 on success, else a driver error code.

To be reimplemented: the default does nothing.

on_samples_ready(data: ndarray)[source]

A block of samples shaped (channels, samples); only if the task was started with notify_every=n.

To be reimplemented: the default does nothing.

class pymodaq_plugins_daqmx.hardware.national_instruments.api.AnalogOutputTask(config: TaskConfig)[source]

Bases: _Task

write_analog(data: float | Sequence[float] | ndarray) → None[source]

Write a DC level (scalar, single channel) or samples: 1D for one channel, 2D (channels, samples).

A scalar is written and started at once; samples are written without starting the task.

write_levels(levels: Sequence[float]) → None[source]

Set every output to a DC level at once, and start the task.

levels holds one level (volts or amperes) per channel, in the order of the channels of the task.

class pymodaq_plugins_daqmx.hardware.national_instruments.api.CounterInputTask(config: TaskConfig)[source]

Bases: _Task

read_counter(samples: int | None = None) → ndarray[source]

Read counter values as a float64 array shaped (counters, samples).

samples defaults to the number of samples of the clock, or 1 when the task has no clock.

class pymodaq_plugins_daqmx.hardware.national_instruments.api.CounterOutputTask(config: TaskConfig)[source]

Bases: _Task

Generates pulses: start() it, close() it to stop.

class pymodaq_plugins_daqmx.hardware.national_instruments.api.DigitalTask(config: TaskConfig)[source]

Bases: _Task

Reads digital input lines or drives digital output lines (not both in one task).

__init__(config: TaskConfig)[source]
read_digital(samples: int = 1) → ndarray[source]

Read the levels as a boolean array shaped (lines, samples).

write_digital(levels: bool | Sequence[bool]) → None[source]

Drive the lines now: a bool for a single line, else one bool per line.

class pymodaq_plugins_daqmx.hardware.national_instruments.api.TaskGroup(*tasks: _Task)[source]

Bases: object

Tasks that run together, such as a task waiting for a clock and the counter that generates it.

One task cannot mix subsystems (analog in, analog out, digital, counters): to acquire and generate at the same time, use one task per subsystem, synchronised by a shared clock or trigger (ClockSettings.source, DigitalEdgeTrigger). The group starts them in the order given, so put first the tasks that wait for a signal and last the one that produces it, and stops and closes them in the reverse order.

If a task cannot start, the ones already started are stopped and the error is raised. All the tasks are closed even if one of them cannot be, then the first error is raised.

__init__(*tasks: _Task)[source]

Channels

class pymodaq_plugins_daqmx.hardware.national_instruments.api.AIVoltage(name: str, min_val: float = -10.0, max_val: float = 10.0, terminal_config: TerminalConfiguration = TerminalConfiguration.DEFAULT)[source]

Bases: object

Analog input measuring a voltage on a physical channel such as Dev1/ai0.

__init__(name: str, min_val: float = -10.0, max_val: float = 10.0, terminal_config: TerminalConfiguration = TerminalConfiguration.DEFAULT) → None
class pymodaq_plugins_daqmx.hardware.national_instruments.api.AICurrent(name: str, min_val: float = -0.02, max_val: float = 0.02, terminal_config: TerminalConfiguration = TerminalConfiguration.DEFAULT)[source]

Bases: object

Analog input measuring a current, in amperes.

__init__(name: str, min_val: float = -0.02, max_val: float = 0.02, terminal_config: TerminalConfiguration = TerminalConfiguration.DEFAULT) → None
class pymodaq_plugins_daqmx.hardware.national_instruments.api.AIThermocouple(name: str, thermocouple_type: ThermocoupleType = ThermocoupleType.K, units: TemperatureUnits = TemperatureUnits.DEG_C, min_val: float = 0.0, max_val: float = 100.0)[source]

Bases: object

Analog input measuring a temperature with a thermocouple (no terminal configuration).

__init__(name: str, thermocouple_type: ThermocoupleType = ThermocoupleType.K, units: TemperatureUnits = TemperatureUnits.DEG_C, min_val: float = 0.0, max_val: float = 100.0) → None
class pymodaq_plugins_daqmx.hardware.national_instruments.api.AIRtd(name: str, rtd_type: RTDType = RTDType.PT_3851, resistance_config: ResistanceConfiguration = ResistanceConfiguration.THREE_WIRE, excitation_current: float = 0.0025, r_0: float = 100.0, units: TemperatureUnits = TemperatureUnits.DEG_C, min_val: float = 0.0, max_val: float = 100.0)[source]

Bases: object

Analog input measuring a temperature with a resistance temperature detector.

__init__(name: str, rtd_type: RTDType = RTDType.PT_3851, resistance_config: ResistanceConfiguration = ResistanceConfiguration.THREE_WIRE, excitation_current: float = 0.0025, r_0: float = 100.0, units: TemperatureUnits = TemperatureUnits.DEG_C, min_val: float = 0.0, max_val: float = 100.0) → None
class pymodaq_plugins_daqmx.hardware.national_instruments.api.AOVoltage(name: str, min_val: float = -10.0, max_val: float = 10.0)[source]

Bases: object

Analog output generating a voltage on a physical channel such as Dev2/ao0.

__init__(name: str, min_val: float = -10.0, max_val: float = 10.0) → None
class pymodaq_plugins_daqmx.hardware.national_instruments.api.AOCurrent(name: str, min_val: float = 0.0, max_val: float = 0.02)[source]

Bases: object

Analog output generating a current, in amperes.

__init__(name: str, min_val: float = 0.0, max_val: float = 0.02) → None
class pymodaq_plugins_daqmx.hardware.national_instruments.api.CICountEdges(name: str, edge: Edge = Edge.RISING, initial_count: int = 0, direction: CountDirection = CountDirection.COUNT_UP)[source]

Bases: object

Counter input counting the edges of a signal, starting from initial_count.

__init__(name: str, edge: Edge = Edge.RISING, initial_count: int = 0, direction: CountDirection = CountDirection.COUNT_UP) → None
class pymodaq_plugins_daqmx.hardware.national_instruments.api.COPulseFreq(name: str, frequency: float, duty_cycle: float = 0.5, idle_state: Level = Level.LOW, initial_delay: float = 0.0)[source]

Bases: object

Counter output generating a pulse train of the given frequency (Hz) and duty cycle (0 to 1, excluded).

__init__(name: str, frequency: float, duty_cycle: float = 0.5, idle_state: Level = Level.LOW, initial_delay: float = 0.0) → None
class pymodaq_plugins_daqmx.hardware.national_instruments.api.DigitalIn(name: str)[source]

Bases: object

Digital input on one line such as Dev1/port0/line0.

__init__(name: str) → None
class pymodaq_plugins_daqmx.hardware.national_instruments.api.DigitalOut(name: str)[source]

Bases: object

Digital output on one line such as Dev1/port0/line3.

__init__(name: str) → None

Timing and triggers

class pymodaq_plugins_daqmx.hardware.national_instruments.api.ClockSettings(rate: float, samples: int | None = None, source: str = '', edge: Edge = Edge.RISING)[source]

Bases: object

Acquire samples samples per channel at rate Hz, or until stopped if samples is None.

source is a terminal such as /Dev1/PFI1 to use an external clock; empty means the onboard clock. A continuous acquisition (no samples) is read through on_samples_ready (start(notify_every=n)), with a driver buffer holding at least one second of data.

__init__(rate: float, samples: int | None = None, source: str = '', edge: Edge = Edge.RISING) → None
class pymodaq_plugins_daqmx.hardware.national_instruments.api.ImplicitTiming(samples: int | None = None)[source]

Bases: object

No sample clock: the pace is given by the task itself, not by the onboard clock.

Use it for counter output: the counter itself generates the pulse train (continuous, or samples pulses). For a counter input that is read on demand, give no timing at all (timing=None): each read returns the count at the moment of the call. To count at a regular pace, use ClockSettings with a source.

__init__(samples: int | None = None) → None
class pymodaq_plugins_daqmx.hardware.national_instruments.api.ChangeDetectionSettings(rising_lines: Tuple[str, ...] = (), falling_lines: Tuple[str, ...] = (), samples: int | None = None)[source]

Bases: object

Sample a digital input task on transitions of the chosen lines, instead of on a clock.

Example: TaskConfig((DigitalIn('Dev1/port0/line0'),), timing=ChangeDetectionSettings(rising_lines=('Dev1/port0/line0',))), run with a DigitalTask. Continuous unless samples is given.

__init__(rising_lines: Tuple[str, ...] = (), falling_lines: Tuple[str, ...] = (), samples: int | None = None) → None
pymodaq_plugins_daqmx.hardware.national_instruments.api.counter_output_terminal(counter: str) → str[source]

The terminal where a counter output sends its pulses, such as /Dev1/Ctr1InternalOutput for Dev1/ctr1: give it as source of a ClockSettings to clock another task with these pulses.

class pymodaq_plugins_daqmx.hardware.national_instruments.api.DigitalEdgeTrigger(source: str, edge: Edge = Edge.RISING)[source]

Bases: object

Start on an edge of a digital terminal such as /Dev1/PFI0.

__init__(source: str, edge: Edge = Edge.RISING) → None
class pymodaq_plugins_daqmx.hardware.national_instruments.api.AnalogEdgeTrigger(source: str, level: float, slope: Slope = Slope.RISING)[source]

Bases: object

Start when the analog signal source (a channel such as Dev1/ai0) crosses level.

__init__(source: str, level: float, slope: Slope = Slope.RISING) → None