pylablib.devices.NI package¶
Submodules¶
pylablib.devices.NI.daq module¶
-
exception
pylablib.devices.NI.daq.
NIError
[source]¶ Bases:
pylablib.core.devio.base.DeviceError
Generic NI error
-
args
¶
-
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
exception
pylablib.devices.NI.daq.
NIDAQmxError
(exc)[source]¶ Bases:
pylablib.devices.NI.daq.NIError
,pylablib.core.devio.comm_backend.DeviceBackendError
NI DAQmx backend operation error
-
args
¶
-
with_traceback
()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
class
pylablib.devices.NI.daq.
TDeviceInfo
(name, model, serial_number)¶ Bases:
tuple
-
count
()¶ Return number of occurrences of value.
-
index
()¶ Return first index of value.
Raises ValueError if the value is not present.
-
model
¶
-
name
¶
-
serial_number
¶
-
-
class
pylablib.devices.NI.daq.
TVoltageOutputClockParameters
(rate, sync_with_ai, continuous, samps_per_chan, autoloop)¶ Bases:
tuple
-
autoloop
¶
-
continuous
¶
-
count
()¶ Return number of occurrences of value.
-
index
()¶ Return first index of value.
Raises ValueError if the value is not present.
-
rate
¶
-
samps_per_chan
¶
-
sync_with_ai
¶
-
-
pylablib.devices.NI.daq.
get_device_info
(name)[source]¶ Get device info.
Return tuple
(name, model, serial)
.
-
class
pylablib.devices.NI.daq.
NIDAQ
(dev_name='dev0', rate=100.0, buffer_size=100000.0, reset=False)[source]¶ Bases:
pylablib.core.devio.interface.IDevice
National Instruments DAQ device interface (wrapper around nidaqmx library).
Simplified interface to NI DAQ devices. Supports voltage, digital, and counter inputs (all synchronized to the same clock), and digital and voltage outputs (asynchronous).
Parameters: -
ReraiseError
¶ alias of
NIDAQmxError
-
BackendError
¶ Used by autodoc_mock_imports.
-
setup_clock
(rate, src=None)[source]¶ Setup analog input clock (which is the main system clock).
If
src==None
, use internal clock with the given rate; otherwise use src terminal as a clock source (in this case, rate should be higher than the expected source rate).
-
export_clock
(terminal)[source]¶ Export system clock to the given terminal (
None
to disconnect all terminals)Only terminal one can be active at a time.
-
get_export_clock_terminal
()[source]¶ Return terminal which outputs system clock (
None
if none is connected)
-
add_voltage_input
(name, channel, rng=(-10, 10), terminal_cfg='default')[source]¶ Add analog voltage input.
Readout is synchronized to the system clock.
Parameters: - name (str) – channel name to refer to it later.
- channel (str) – terminal name (e.g.,
"ai0"
). - rng – voltage range
- terminal_cfg – terminal configuration; can be
"default"
,"rse"
(single-ended, referenced to AI SENSE input),"nrse"
(single-ended, referenced to AI GND),"diff"
(differential), or"pseudodiff"
(see NI DAQ manual for details).
-
add_counter_input
(name, counter, terminal, clk_src='ai/SampleClock', output_format='rate')[source]¶ Add counter input (value is related to the number of counts).
Readout is synchronized to the system clock.
Parameters: - name (str) – channel name.
- counter (str) – on-board counter name (e.g.,
"ctr0"
). - terminal (str) – terminal name (e.g.,
"pfi0"
). - clk_src (str) – source of the counter sampling clock. By default it is the analog input clock, which requires at least one voltage input channel (could be a dummy channel) to be set up first.
- output_format (str) – output format. Can be
"acc"
(return accumulated number of counts since the sampling start),"diff"
(return number of counts passed between the two consecutive sampling points; essentially, a derivative of"acc"
), or"rate"
(return count rate based on the"diff"
samples).
-
add_clock_period_input
(counter, clk_src='ai/SampleClock')[source]¶ Add clock period counter.
Useful when using external sample clock with unknown period. The clock input can be returned during
read()
operation, and it is used to calculate counter inputs in"rate"
mode. Readout is synchronized to the system clock.Parameters:
-
add_digital_input
(name, channel)[source]¶ Add digital input.
Readout is synchronized to the system clock. :param name: channel name. :type name: str :param channel: terminal name (e.g.,
"port0/line12"
). :type channel: str
-
get_input_channels
(include=('ai', 'ci', 'di'))[source]¶ Get names of all input channels (voltage input and counter input).
include specifies which channel types to include into the list (
"ai"
for voltage inputs,"ci"
for counter inputs,"di"
for digital inputs,"cpi"
for clock period channel). The channels order is always fixed: first voltage inputs, then counter inputs, then digital inputs.
-
get_voltage_input_parameters
()[source]¶ Get parameters (names, channels, output ranges, and terminal configurations) of all analog voltage input channels
-
get_counter_input_parameters
()[source]¶ Get parameters (names, counters, terminals, clock sources, and output formats) of all counter input channels
-
get_digital_input_parameters
()[source]¶ Get parameters (names and channels) of all digital input channels
-
get_clock_period_input_parameters
()[source]¶ Get parameters (counter input) of the clock period input channel
-
start
(flush_read=0, finite=None)[source]¶ Start the sampling and output task.
flush_read specifies number of samples to read and discard after start. If finite is not
None
, it specifies finite number of sample to acquire before stopping.If counter channels are used, the first sample is usually unreliable, so
flush_read=1
is recommended; however, if exactly finite pulses are required at the clock export channel,flush_read=0
is needed (the total number of pulses isflush_read+finite
).
-
available_samples
()[source]¶ Get number of available samples to read (return 0 if the task is not running)
-
wait_for_sample
(num=1, timeout=10.0, wait_time=0.001)[source]¶ Wait until at least num samples are available.
If they are not available immediately, loop while checking every wait_time interval until enough samples are accumulated. Return the number of available samples if successful, or 0 if the execution timed out.
-
read
(n=1, flush_read=0, timeout=10.0, include=('ai', 'ci', 'di'))[source]¶ Read n samples. If the task is not running, automatically start before reading and stop after.
Parameters: - n (int) – number of samples to read. If
n<=0
, read all available samples. - flush_read (int) – number of initial samples to skip if the task is currently stopped and needs to be started.
If counter channels are used, the first sample is usually unreliable, so
flush_read=1
is recommended; however, if exactly n pulses are required at the clock export channel,flush_read=0
is needed. - include (tuple) – specifies which channel types to include into the list
(
"ai"
for voltage inputs,"ci"
for counter inputs,"di"
for digital inputs,"cpi"
for clock period channel).
Returns: 2D numpy array of values arranged according to
get_input_channels()
order with the given include parameter.- n (int) – number of samples to read. If
-
get_digital_output_parameters
()[source]¶ Get parameters (names and channels) of all digital output channels
-
set_digital_outputs
(names, values)[source]¶ Set values of one or several digital outputs.
Parameters:
-
get_digital_outputs
(names=None)[source]¶ Get values of one or several digital outputs.
Parameters: names (str or [str] or None) – name or list of names of outputs ( None
means all outputs).Return list of values ordered by names (or by
get_digital_output_channels()
ifnames==None
).
-
add_voltage_output
(name, channel, rng=(-10, 10), initial_value=0.0)[source]¶ Add analog voltage output.
Parameters:
-
get_voltage_output_parameters
()[source]¶ Get parameters (names, channels and output ranges) of all analog voltage output channels
-
set_voltage_outputs
(names, values, minsamp=1, force_restart=True, single_shot=0)[source]¶ Set values of one or several analog voltage outputs.
Parameters: - names (str or [str]) – name or list of names of outputs.
- values – output value or list values.
These can be single numbers, or arrays if the output clock is setup (see
setup_voltage_output_clock()
). In the latter case it sets up the output waveforms; note that waveforms for all channels must have the same length (a single number signifying a constant output is also allowed) If the analog output is set up to the finite mode (continuous==False
), the finite waveform output happens right away, with the number of samples determined by samps_per_channel parameter ofsetup_voltage_output_clock()
. In this case, if the supplied waveform is shorter than the number of samples, it gets repeated; if it’s longer, it gets cut off. - minsamp – in non-autoloop mode, specifies the minimal number of samples to write to the output buffer; if the length of values is less than this number, than the waveform is repeated by a required integer number of times to produce at least minsamp samples
- force_restart – if
True
, restart the output after writing to immediately start outputting the new waveforms; otherwise, add it to the end of the buffer; only applies in non-autoloop mode (autoloop mode always restarts) - single_shot – specifies some number of samples from the start as “single-shot”, so whenever the waveform is repeated
(either to reach minsamp samples, or when
fill_voltage_output_buffer()
is called), this part is ignored, and only the rest is repeated
-
get_voltage_output_buffer_fill
()[source]¶ Get the number of samples still in the output buffer.
Only applies to non-autoloop mode, and return
None
otherwise.
-
fill_voltage_output_buffer
(minsamp=1)[source]¶ Add samples to the output buffer until there are at least minsamp samples there.
Only applies to non-autoloop mode, and does nothing otherwise. The added samples are determined based on the last data written by
set_voltage_outputs()
and thesingle_shot
argument specified there.
-
get_voltage_outputs
(names=None)[source]¶ Get values of one or several analog voltage outputs.
Parameters: names (str or [str] or None) – name or list of names of outputs ( None
means all outputs).Return list of values ordered by names (or by
get_voltage_output_channels()
ifnames==None
). For continuous waveforms, return the array containing a single repetition of the waveform. For finite waveforms, repeat the array containing the last outputted waveform.
-
class
NoParameterCaller
(device, kind)¶ Bases:
object
Class to simplify calling functions without a parameter
-
apply_settings
(settings)¶ Apply the settings.
settings is the dict
{name: value}
of the device available settings. Non-applicable settings are ignored.
-
get_device_variable
(key)¶ Get the value of a settings, status, or full info parameter
-
get_full_info
(include=0)¶ Get dict
{name: value}
containing full device information (including status and settings).include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or
"all"
(all available variables). Since the lowest priority is -10, settinginclude=-10
queries all available variables, which is equivalent toinclude="all"
.
-
get_full_status
(include=0)¶ Get dict
{name: value}
containing the device status (including settings).include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or
"all"
(all available variables). Since the lowest priority is -10, settinginclude=-10
queries all available variables, which is equivalent toinclude="all"
.
-
get_settings
(include=0)¶ Get dict
{name: value}
containing all the device settings.include specifies either a list of variables (only these variables are returned), a priority threshold (only values with the priority equal or higher are returned), or
"all"
(all available variables). Since the lowest priority is -10, settinginclude=-10
queries all available variables, which is equivalent toinclude="all"
.
-
set_device_variable
(key, value)¶ Set the value of a settings parameter
-
setup_voltage_output_clock
(rate=0, sync_with_ai=False, continuous=True, samps_per_chan=1000, autoloop=True, minsamp=1)[source]¶ Setup analog output clock configuration.
Parameters: - rate – clock rate; if 0, assume constant voltage output (default)
- sync_with_ai – if
True
, the clock is synchronized to the analog input clock (the main clock); note that in this case output changes only when the analog read task is running - continuous – if
True
, any written waveform gets repeated continuously; otherwise, it outputs written waveform only once, and then latches the output on the last value - samps_per_chan – if
continuous==False
, it determines number of samples to output before stopping; otherwise, it determines the size of the output buffer - autoloop – if it is
True
, then the specified output waveforms are automatically repeated to create a periodic output signal (referred to as “regeneration mode” in NI DAQ terminology); otherwise, written output data is “exhausted” once sent to the output, so the application needs to continuously write output waveforms to avoid output buffer from running empty (which causes an error). This mode gives better control over the output and allows to seamlessly adjust it in real time, but it is more demanding on the application. - minsamp – if the waveform has been specified before, this argument sets the minimal number of samples to write to the output buffer after the clock is set up and the output is restarted
-