from typing import Optional, Tuple
import numpy
from nidaqmx import DaqError
from nidaqmx.constants import FillMode, READ_ALL_AVAILABLE
from nidaqmx.error_codes import DAQmxErrors
from nidaqmx.types import PowerMeasurement, CtrFreq, CtrTick, CtrTime
__all__ = ['AnalogSingleChannelReader', 'AnalogMultiChannelReader',
'AnalogUnscaledReader', 'CounterReader',
'DigitalSingleChannelReader', 'DigitalMultiChannelReader',
'PowerSingleChannelReader', 'PowerMultiChannelReader', 'PowerBinaryReader']
class ChannelReaderBase:
"""
Defines base class for all NI-DAQmx stream readers.
"""
def __init__(self, task_in_stream):
"""
Args:
task_in_stream: Specifies the input stream associated with
an NI-DAQmx task from which to read samples.
"""
self._in_stream = task_in_stream
self._task = task_in_stream._task
self._handle = task_in_stream._task._handle
self._interpreter = task_in_stream._task._interpreter
self._verify_array_shape = True
@property
def verify_array_shape(self):
"""
bool: Indicates whether the size and shape of the user-defined
NumPy arrays passed to read methods are verified. Defaults
to True when this object is instantiated.
Setting this property to True may marginally adversely
impact the performance of read methods.
"""
return self._verify_array_shape
@verify_array_shape.setter
def verify_array_shape(self, val):
self._verify_array_shape = val
def _verify_array(self, data, number_of_samples_per_channel,
is_many_chan, is_many_samp):
"""
Verifies that the shape of the specified NumPy array can be used
to read multiple samples from the current task which contains
one or more channels, if the "verify_array_shape" property is
set to True.
Args:
data (numpy.ndarray): Specifies the NumPy array to verify.
number_of_samples_per_channel (int): Specifies the number of
samples per channel requested.
is_many_chan (bool): Specifies if the read method is a many
channel version.
is_many_samp (bool): Specifies if the read method is a many
samples version.
"""
if not self._verify_array_shape:
return
channels_to_read = self._in_stream.channels_to_read
number_of_channels = len(channels_to_read.channel_names)
array_shape: Optional[Tuple[int, ...]] = None
if is_many_chan:
if is_many_samp:
array_shape = (number_of_channels,
number_of_samples_per_channel)
else:
array_shape = (number_of_channels,)
else:
if is_many_samp:
array_shape = (number_of_samples_per_channel,)
if array_shape is not None and data.shape != array_shape:
raise DaqError(
'Read cannot be performed because the NumPy array passed into '
'this function is not shaped correctly. You must pass in a '
'NumPy array of the correct shape based on the number of '
'channels in task and the number of samples per channel '
'requested.\n\n'
'Shape of NumPy Array provided: {}\n'
'Shape of NumPy Array required: {}'
.format(data.shape, array_shape),
DAQmxErrors.UNKNOWN, task_name=self._task.name)
def _verify_array_digital_lines(
self, data, is_many_chan, is_many_line):
"""
Verifies that the shape of the specified NumPy array can be used
to read samples from the current task which contains one or more
channels that have one or more digital lines per channel, if the
"verify_array_shape" property is set to True.
Args:
data (numpy.ndarray): Specifies the NumPy array to verify.
is_many_chan (bool): Specifies if the read method is a
many channel version.
is_many_line (bool): Specifies if the read method is a
many line version.
"""
if not self._verify_array_shape:
return
channels_to_read = self._in_stream.channels_to_read
number_of_channels = len(channels_to_read.channel_names)
number_of_lines = self._in_stream.di_num_booleans_per_chan
array_shape: Optional[Tuple[int, ...]] = None
if is_many_chan:
if is_many_line:
array_shape = (number_of_channels, number_of_lines)
else:
array_shape = (number_of_channels,)
else:
if is_many_line:
array_shape = (number_of_lines,)
if array_shape is not None and data.shape != array_shape:
raise DaqError(
'Read cannot be performed because the NumPy array passed into '
'this function is not shaped correctly. You must pass in a '
'NumPy array of the correct shape based on the number of '
'channels in task and the number of digital lines per '
'channel.\n\n'
'Shape of NumPy Array provided: {}\n'
'Shape of NumPy Array required: {}'
.format(data.shape, array_shape),
DAQmxErrors.UNKNOWN, task_name=self._task.name)
[docs]
class AnalogSingleChannelReader(ChannelReaderBase):
"""
Reads samples from an analog input channel in an NI-DAQmx task.
"""
[docs]
def read_many_sample(
self, data, number_of_samples_per_channel=READ_ALL_AVAILABLE,
timeout=10.0):
"""
Reads one or more floating-point samples from a single analog
input channel in a task.
This read method accepts a preallocated NumPy array to hold the
samples requested, which can be advantageous for performance and
interoperability with NumPy and SciPy.
Passing in a preallocated array is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
data (numpy.ndarray): Specifies a preallocated 1D NumPy
array of floating-point values to hold the samples
requested.
Each element in the array corresponds to a sample from
the channel. The size of the array must be large enough
to hold all requested samples from the channel in the
task; otherwise, an error is thrown.
number_of_samples_per_channel (Optional[int]): Specifies the
number of samples to read.
If you set this input to nidaqmx.constants.
READ_ALL_AVAILABLE, NI-DAQmx determines how many samples
to read based on if the task acquires samples
continuously or acquires a finite number of samples.
If the task acquires samples continuously and you set
this input to nidaqmx.constants.READ_ALL_AVAILABLE, this
method reads all the samples currently available in the
buffer.
If the task acquires a finite number of samples and you
set this input to nidaqmx.constants.READ_ALL_AVAILABLE,
the method waits for the task to acquire all requested
samples, then reads those samples. If you set the
"read_all_avail_samp" property to True, the method reads
the samples currently available in the buffer and does
not wait for the task to acquire all requested samples.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
int:
Indicates the number of samples acquired by each channel.
NI-DAQmx returns a single value because this value is the
same for all channels.
"""
number_of_samples_per_channel = (
self._task._calculate_num_samps_per_chan(
number_of_samples_per_channel))
self._verify_array(data, number_of_samples_per_channel, False, True)
_, samps_per_chan_read = self._interpreter.read_analog_f64(
self._handle, number_of_samples_per_channel,
timeout, FillMode.GROUP_BY_CHANNEL.value, data)
return samps_per_chan_read
[docs]
def read_one_sample(self, timeout=10):
"""
Reads a single floating-point sample from a single analog input
channel in a task.
Args:
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
float:
Indicates a single floating-point sample from the task.
"""
return self._interpreter.read_analog_scalar_f64(self._handle, timeout)
[docs]
class AnalogMultiChannelReader(ChannelReaderBase):
"""
Reads samples from one or more analog input channels in an NI-DAQmx
task.
"""
[docs]
def read_many_sample(
self, data, number_of_samples_per_channel=READ_ALL_AVAILABLE,
timeout=10.0):
"""
Reads one or more floating-point samples from one or more analog
input channels in a task.
This read method accepts a preallocated NumPy array to hold the
samples requested, which can be advantageous for performance and
interoperability with NumPy and SciPy.
Passing in a preallocated array is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
data (numpy.ndarray): Specifies a preallocated 2D NumPy
array of floating-point values to hold the samples
requested. The size of the array must be large enough to
hold all requested samples from all channels in the
task; otherwise, an error is thrown.
Each row corresponds to a channel in the task. Each
column corresponds to a sample from each channel. The
order of the channels in the array corresponds to the
order in which you add the channels to the task or to
the order of the channels you specify with the
"channels_to_read" property.
If the size of the array is too large or the array is
shaped incorrectly, the previous statement may not hold
true as the samples read may not be separated into rows
and columns properly. Set the "verify_array_shape"
property on this channel reader object to True to
validate that the NumPy array object is shaped properly.
Setting this property to True may marginally adversely
impact the performance of the method.
number_of_samples_per_channel (Optional[int]): Specifies the
number of samples to read.
If you set this input to nidaqmx.constants.
READ_ALL_AVAILABLE, NI-DAQmx determines how many samples
to read based on if the task acquires samples
continuously or acquires a finite number of samples.
If the task acquires samples continuously and you set
this input to nidaqmx.constants.READ_ALL_AVAILABLE, this
method reads all the samples currently available in the
buffer.
If the task acquires a finite number of samples and you
set this input to nidaqmx.constants.READ_ALL_AVAILABLE,
the method waits for the task to acquire all requested
samples, then reads those samples. If you set the
"read_all_avail_samp" property to True, the method reads
the samples currently available in the buffer and does
not wait for the task to acquire all requested samples.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
int:
Indicates the number of samples acquired by each channel.
NI-DAQmx returns a single value because this value is the
same for all channels.
"""
number_of_samples_per_channel = (
self._task._calculate_num_samps_per_chan(
number_of_samples_per_channel))
self._verify_array(data, number_of_samples_per_channel, True, True)
_, samps_per_chan_read = self._interpreter.read_analog_f64(
self._handle, number_of_samples_per_channel,
timeout, FillMode.GROUP_BY_CHANNEL.value, data)
return samps_per_chan_read
[docs]
def read_one_sample(self, data, timeout=10):
"""
Reads a single floating-point sample from one or more analog
input channels in a task.
This read method accepts a preallocated NumPy array to hold the
samples requested, which can be advantageous for performance and
interoperability with NumPy and SciPy.
Passing in a preallocated array is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
data (numpy.ndarray): Specifies a preallocated 1D NumPy
array of floating-point values to hold the samples
requested.
Each element in the array corresponds to a sample from
each channel. The size of the array must be large enough
to hold all requested samples from the channel in the
task; otherwise, an error is thrown.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
"""
self._verify_array(data, 1, True, False)
self._interpreter.read_analog_f64(self._handle, 1, timeout, FillMode.GROUP_BY_CHANNEL.value, data)
[docs]
class AnalogUnscaledReader(ChannelReaderBase):
"""
Reads unscaled samples from one or more analog input channels in an
NI-DAQmx task.
"""
[docs]
def read_int16(
self, data, number_of_samples_per_channel=READ_ALL_AVAILABLE,
timeout=10.0):
"""
Reads one or more unscaled 16-bit integer samples from one or
more analog input channels in a task.
This read method accepts a preallocated NumPy array to hold the
samples requested, which can be advantageous for performance and
interoperability with NumPy and SciPy.
Passing in a preallocated array is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
data (numpy.ndarray): Specifies a preallocated 2D NumPy
array of unscaled 16-bit integer values to hold the
samples requested. The size of the array must be large
enough to hold all requested samples from all channels
in the task; otherwise, an error is thrown.
Each row corresponds to a channel in the task. Each
column corresponds to a sample from each channel. The
order of the channels in the array corresponds to the
order in which you add the channels to the task or to
the order of the channels you specify with the
"channels_to_read" property.
If the size of the array is too large or the array is
shaped incorrectly, the previous statement may not hold
true as the samples read may not be separated into rows
and columns properly. Set the "verify_array_shape"
property on this channel reader object to True to
validate that the NumPy array object is shaped properly.
Setting this property may marginally adversely impact
the performance of the method.
number_of_samples_per_channel (Optional[int]): Specifies the
number of samples to read.
If you set this input to nidaqmx.constants.
READ_ALL_AVAILABLE, NI-DAQmx determines how many samples
to read based on if the task acquires samples
continuously or acquires a finite number of samples.
If the task acquires samples continuously and you set
this input to nidaqmx.constants.READ_ALL_AVAILABLE, this
method reads all the samples currently available in the
buffer.
If the task acquires a finite number of samples and you
set this input to nidaqmx.constants.READ_ALL_AVAILABLE,
the method waits for the task to acquire all requested
samples, then reads those samples. If you set the
"read_all_avail_samp" property to True, the method reads
the samples currently available in the buffer and does
not wait for the task to acquire all requested samples.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
int:
Indicates the number of samples acquired by each channel.
NI-DAQmx returns a single value because this value is the
same for all channels.
"""
number_of_samples_per_channel = (
self._task._calculate_num_samps_per_chan(
number_of_samples_per_channel))
self._verify_array(data, number_of_samples_per_channel, True, True)
_, samps_per_chan_read = self._interpreter.read_binary_i16(
self._handle, number_of_samples_per_channel,
timeout, FillMode.GROUP_BY_CHANNEL.value, data)
return samps_per_chan_read
[docs]
def read_int32(
self, data, number_of_samples_per_channel=READ_ALL_AVAILABLE,
timeout=10.0):
"""
Reads one or more unscaled 32-bit integer samples from one or
more analog input channels in a task.
This read method accepts a preallocated NumPy array to hold the
samples requested, which can be advantageous for performance and
interoperability with NumPy and SciPy.
Passing in a preallocated array is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
data (numpy.ndarray): Specifies a preallocated 2D NumPy
array of unscaled 32-bit integer values to hold the
samples requested. The size of the array must be large
enough to hold all requested samples from all channels
in the task; otherwise, an error is thrown.
Each row corresponds to a channel in the task. Each
column corresponds to a sample from each channel. The
order of the channels in the array corresponds to the
order in which you add the channels to the task or to
the order of the channels you specify with the
"channels_to_read" property.
If the size of the array is too large or the array is
shaped incorrectly, the previous statement may not hold
true as the samples read may not be separated into rows
and columns properly. Set the "verify_array_shape"
property on this channel reader object to True to
validate that the NumPy array object is shaped properly.
Setting this property may marginally adversely impact
the performance of the method.
number_of_samples_per_channel (Optional[int]): Specifies the
number of samples to read.
If you set this input to nidaqmx.constants.
READ_ALL_AVAILABLE, NI-DAQmx determines how many samples
to read based on if the task acquires samples
continuously or acquires a finite number of samples.
If the task acquires samples continuously and you set
this input to nidaqmx.constants.READ_ALL_AVAILABLE, this
method reads all the samples currently available in the
buffer.
If the task acquires a finite number of samples and you
set this input to nidaqmx.constants.READ_ALL_AVAILABLE,
the method waits for the task to acquire all requested
samples, then reads those samples. If you set the
"read_all_avail_samp" property to True, the method reads
the samples currently available in the buffer and does
not wait for the task to acquire all requested samples.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
int:
Indicates the number of samples acquired by each channel.
NI-DAQmx returns a single value because this value is the
same for all channels.
"""
number_of_samples_per_channel = (
self._task._calculate_num_samps_per_chan(
number_of_samples_per_channel))
self._verify_array(data, number_of_samples_per_channel, True, True)
_, samps_per_chan_read = self._interpreter.read_binary_i32(
self._handle, number_of_samples_per_channel,
timeout, FillMode.GROUP_BY_CHANNEL.value, data)
return samps_per_chan_read
[docs]
def read_uint16(
self, data, number_of_samples_per_channel=READ_ALL_AVAILABLE,
timeout=10.0):
"""
Reads one or more unscaled 16-bit unsigned integer samples from
one or more analog input channels in a task.
This read method accepts a preallocated NumPy array to hold the
samples requested, which can be advantageous for performance and
interoperability with NumPy and SciPy.
Passing in a preallocated array is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
data (numpy.ndarray): Specifies a preallocated 2D NumPy
array of unscaled 16-bit unsigned integer values to
hold the samples requested. The size of the array must
be large enough to hold all requested samples from all
channels in the task; otherwise, an error is thrown.
Each row corresponds to a channel in the task. Each
column corresponds to a sample from each channel. The
order of the channels in the array corresponds to the
order in which you add the channels to the task or to
the order of the channels you specify with the
"channels_to_read" property.
If the size of the array is too large or the array is
shaped incorrectly, the previous statement may not hold
true as the samples read may not be separated into rows
and columns properly. Set the "verify_array_shape"
property on this channel reader object to True to
validate that the NumPy array object is shaped properly.
Setting this property may marginally adversely impact
the performance of the method.
number_of_samples_per_channel (Optional[int]): Specifies the
number of samples to read.
If you set this input to nidaqmx.constants.
READ_ALL_AVAILABLE, NI-DAQmx determines how many samples
to read based on if the task acquires samples
continuously or acquires a finite number of samples.
If the task acquires samples continuously and you set
this input to nidaqmx.constants.READ_ALL_AVAILABLE, this
method reads all the samples currently available in the
buffer.
If the task acquires a finite number of samples and you
set this input to nidaqmx.constants.READ_ALL_AVAILABLE,
the method waits for the task to acquire all requested
samples, then reads those samples. If you set the
"read_all_avail_samp" property to True, the method reads
the samples currently available in the buffer and does
not wait for the task to acquire all requested samples.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
int:
Indicates the number of samples acquired by each channel.
NI-DAQmx returns a single value because this value is the
same for all channels.
"""
number_of_samples_per_channel = (
self._task._calculate_num_samps_per_chan(
number_of_samples_per_channel))
self._verify_array(data, number_of_samples_per_channel, True, True)
_, samps_per_chan_read = self._interpreter.read_binary_u16(
self._handle, number_of_samples_per_channel,
timeout, FillMode.GROUP_BY_CHANNEL.value, data)
return samps_per_chan_read
[docs]
def read_uint32(
self, data, number_of_samples_per_channel=READ_ALL_AVAILABLE,
timeout=10.0):
"""
Reads one or more unscaled unsigned 32-bit integer samples from
one or more analog input channels in a task.
This read method accepts a preallocated NumPy array to hold the
samples requested, which can be advantageous for performance and
interoperability with NumPy and SciPy.
Passing in a preallocated array is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
data (numpy.ndarray): Specifies a preallocated 2D NumPy
array of unscaled 32-bit unsigned integer values to
hold the samples requested. The size of the array must
be large enough to hold all requested samples from all
channels in the task; otherwise, an error is thrown.
Each row corresponds to a channel in the task. Each
column corresponds to a sample from each channel. The
order of the channels in the array corresponds to the
order in which you add the channels to the task or to
the order of the channels you specify with the
"channels_to_read" property.
If the size of the array is too large or the array is
shaped incorrectly, the previous statement may not hold
true as the samples read may not be separated into rows
and columns properly. Set the "verify_array_shape"
property on this channel reader object to True to
validate that the NumPy array object is shaped properly.
Setting this property may marginally adversely impact
the performance of the method.
number_of_samples_per_channel (Optional[int]): Specifies the
number of samples to read.
If you set this input to nidaqmx.constants.
READ_ALL_AVAILABLE, NI-DAQmx determines how many samples
to read based on if the task acquires samples
continuously or acquires a finite number of samples.
If the task acquires samples continuously and you set
this input to nidaqmx.constants.READ_ALL_AVAILABLE, this
method reads all the samples currently available in the
buffer.
If the task acquires a finite number of samples and you
set this input to nidaqmx.constants.READ_ALL_AVAILABLE,
the method waits for the task to acquire all requested
samples, then reads those samples. If you set the
"read_all_avail_samp" property to True, the method reads
the samples currently available in the buffer and does
not wait for the task to acquire all requested samples.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
int:
Indicates the number of samples acquired by each channel.
NI-DAQmx returns a single value because this value is the
same for all channels.
"""
number_of_samples_per_channel = (
self._task._calculate_num_samps_per_chan(
number_of_samples_per_channel))
self._verify_array(data, number_of_samples_per_channel, True, True)
_, samps_per_chan_read = self._interpreter.read_binary_u32(
self._handle, number_of_samples_per_channel,
timeout, FillMode.GROUP_BY_CHANNEL.value, data)
return samps_per_chan_read
[docs]
class PowerSingleChannelReader(ChannelReaderBase):
"""
Reads samples from an analog input power channel in an NI-DAQmx task.
"""
[docs]
def read_many_sample(
self, voltage_data, current_data, number_of_samples_per_channel=READ_ALL_AVAILABLE,
timeout=10.0):
"""
Reads one or more floating-point power samples from a single analog
input power channel in a task.
This read method accepts a preallocated NumPy array to hold the
samples requested, which can be advantageous for performance and
interoperability with NumPy and SciPy.
Passing in a preallocated array is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
voltage_data (numpy.ndarray): Specifies a preallocated 1D NumPy
array of floating-point values to hold the voltage samples
requested.
Each element in the array corresponds to a sample from
the channel. The size of the array must be large enough
to hold all requested samples from the channel in the
task; otherwise, an error is thrown.
current_data (numpy.ndarray): Specifies a preallocated 1D NumPy
array of floating-point values to hold the current samples
requested.
Each element in the array corresponds to a sample from
the channel. The size of the array must be large enough
to hold all requested samples from the channel in the
task; otherwise, an error is thrown.
number_of_samples_per_channel (Optional[int]): Specifies the
number of samples to read.
If you set this input to nidaqmx.constants.
READ_ALL_AVAILABLE, NI-DAQmx determines how many samples
to read based on if the task acquires samples
continuously or acquires a finite number of samples.
If the task acquires samples continuously and you set
this input to nidaqmx.constants.READ_ALL_AVAILABLE, this
method reads all the samples currently available in the
buffer.
If the task acquires a finite number of samples and you
set this input to nidaqmx.constants.READ_ALL_AVAILABLE,
the method waits for the task to acquire all requested
samples, then reads those samples. If you set the
"read_all_avail_samp" property to True, the method reads
the samples currently available in the buffer and does
not wait for the task to acquire all requested samples.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
int:
Indicates the number of samples acquired by each channel.
NI-DAQmx returns a single value because this value is the
same for all channels.
"""
number_of_samples_per_channel = (
self._task._calculate_num_samps_per_chan(
number_of_samples_per_channel))
self._verify_array(voltage_data, number_of_samples_per_channel, False, True)
self._verify_array(current_data, number_of_samples_per_channel, False, True)
_, _, samps_per_chan_read = self._interpreter.read_power_f64(
self._handle, number_of_samples_per_channel, timeout,
FillMode.GROUP_BY_CHANNEL.value, voltage_data, current_data)
return samps_per_chan_read
[docs]
def read_one_sample(self, timeout=10):
"""
Reads a single floating-point power sample from a single analog input
power channel in a task.
Args:
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
float:
Indicates a single floating-point power sample from the task.
"""
voltage, current = self._interpreter.read_power_scalar_f64(self._handle, timeout)
return PowerMeasurement(voltage=voltage, current=current)
[docs]
class PowerMultiChannelReader(ChannelReaderBase):
"""
Reads samples from one or more analog input power channels in an NI-DAQmx
task.
"""
[docs]
def read_many_sample(
self, voltage_data, current_data, number_of_samples_per_channel=READ_ALL_AVAILABLE,
timeout=10.0):
"""
Reads one or more floating-point power samples from one or more analog
input power channels in a task.
This read method accepts a preallocated NumPy array to hold the
samples requested, which can be advantageous for performance and
interoperability with NumPy and SciPy.
Passing in a preallocated array is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
voltage_data (numpy.ndarray): Specifies a preallocated 2D NumPy
array of floating-point values to hold the voltage samples
requested. The size of the array must be large enough to
hold all requested samples from all channels in the
task; otherwise, an error is thrown.
Each row corresponds to a channel in the task. Each
column corresponds to a sample from each channel. The
order of the channels in the array corresponds to the
order in which you add the channels to the task or to
the order of the channels you specify with the
"channels_to_read" property.
If the size of the array is too large or the array is
shaped incorrectly, the previous statement may not hold
true as the samples read may not be separated into rows
and columns properly. Set the "verify_array_shape"
property on this channel reader object to True to
validate that the NumPy array object is shaped properly.
Setting this property to True may marginally adversely
impact the performance of the method.
current_data (numpy.ndarray): Specifies a preallocated 2D NumPy
array of floating-point values to hold the current samples
requested. The size of the array must be large enough to
hold all requested samples from all channels in the
task; otherwise, an error is thrown.
Each row corresponds to a channel in the task. Each
column corresponds to a sample from each channel. The
order of the channels in the array corresponds to the
order in which you add the channels to the task or to
the order of the channels you specify with the
"channels_to_read" property.
If the size of the array is too large or the array is
shaped incorrectly, the previous statement may not hold
true as the samples read may not be separated into rows
and columns properly. Set the "verify_array_shape"
property on this channel reader object to True to
validate that the NumPy array object is shaped properly.
Setting this property to True may marginally adversely
impact the performance of the method.
number_of_samples_per_channel (Optional[int]): Specifies the
number of samples to read.
If you set this input to nidaqmx.constants.
READ_ALL_AVAILABLE, NI-DAQmx determines how many samples
to read based on if the task acquires samples
continuously or acquires a finite number of samples.
If the task acquires samples continuously and you set
this input to nidaqmx.constants.READ_ALL_AVAILABLE, this
method reads all the samples currently available in the
buffer.
If the task acquires a finite number of samples and you
set this input to nidaqmx.constants.READ_ALL_AVAILABLE,
the method waits for the task to acquire all requested
samples, then reads those samples. If you set the
"read_all_avail_samp" property to True, the method reads
the samples currently available in the buffer and does
not wait for the task to acquire all requested samples.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
int:
Indicates the number of samples acquired by each channel.
NI-DAQmx returns a single value because this value is the
same for all channels.
"""
number_of_samples_per_channel = (
self._task._calculate_num_samps_per_chan(
number_of_samples_per_channel))
self._verify_array(voltage_data, number_of_samples_per_channel, True, True)
self._verify_array(current_data, number_of_samples_per_channel, True, True)
_, _, samps_per_chan_read = self._interpreter.read_power_f64(
self._handle, number_of_samples_per_channel, timeout,
FillMode.GROUP_BY_CHANNEL.value, voltage_data, current_data)
return samps_per_chan_read
[docs]
def read_one_sample(self, voltage_data, current_data, timeout=10):
"""
Reads a single floating-point power sample from one or more analog
input channels in a task.
This read method accepts a preallocated NumPy array to hold the
samples requested, which can be advantageous for performance and
interoperability with NumPy and SciPy.
Passing in a preallocated array is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
voltage_data (numpy.ndarray): Specifies a preallocated 1D NumPy
array of floating-point values to hold the voltage samples
requested.
Each element in the array corresponds to a sample from
each channel. The size of the array must be large enough
to hold all requested samples from the channel in the
task; otherwise, an error is thrown.
current_data (numpy.ndarray): Specifies a preallocated 1D NumPy
array of floating-point values to hold the voltage samples
requested.
Each element in the array corresponds to a sample from
each channel. The size of the array must be large enough
to hold all requested samples from the channel in the
task; otherwise, an error is thrown.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
"""
self._verify_array(voltage_data, 1, True, False)
self._verify_array(current_data, 1, True, False)
self._interpreter.read_power_f64(
self._handle, 1, timeout, FillMode.GROUP_BY_CHANNEL.value,
voltage_data, current_data)
[docs]
class PowerBinaryReader(ChannelReaderBase):
"""
Reads binary samples from one or more analog input power channels in an
NI-DAQmx task.
"""
[docs]
def read_many_sample(
self, voltage_data, current_data, number_of_samples_per_channel=READ_ALL_AVAILABLE,
timeout=10.0):
"""
Reads one or more binary int16 samples from one or more analog
input power channel in a task.
This read method accepts a preallocated NumPy array to hold the
samples requested, which can be advantageous for performance and
interoperability with NumPy and SciPy.
Passing in a preallocated array is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
voltage_data (numpy.ndarray): Specifies a preallocated 1D NumPy
array of i16 values to hold the voltage samples requested.
Each row corresponds to a channel in the task. Each
column corresponds to a sample from each channel. The
order of the channels in the array corresponds to the
order in which you add the channels to the task or to
the order of the channels you specify with the
"channels_to_read" property.
If the size of the array is too large or the array is
shaped incorrectly, the previous statement may not hold
true as the samples read may not be separated into rows
and columns properly. Set the "verify_array_shape"
property on this channel reader object to True to
validate that the NumPy array object is shaped properly.
Setting this property to True may marginally adversely
impact the performance of the method.
current_data (numpy.ndarray): Specifies a preallocated 1D NumPy
array of i16 values to hold the current samples requested.
Each row corresponds to a channel in the task. Each
column corresponds to a sample from each channel. The
order of the channels in the array corresponds to the
order in which you add the channels to the task or to
the order of the channels you specify with the
"channels_to_read" property.
If the size of the array is too large or the array is
shaped incorrectly, the previous statement may not hold
true as the samples read may not be separated into rows
and columns properly. Set the "verify_array_shape"
property on this channel reader object to True to
validate that the NumPy array object is shaped properly.
Setting this property to True may marginally adversely
impact the performance of the method.
number_of_samples_per_channel (Optional[int]): Specifies the
number of samples to read.
If you set this input to nidaqmx.constants.
READ_ALL_AVAILABLE, NI-DAQmx determines how many samples
to read based on if the task acquires samples
continuously or acquires a finite number of samples.
If the task acquires samples continuously and you set
this input to nidaqmx.constants.READ_ALL_AVAILABLE, this
method reads all the samples currently available in the
buffer.
If the task acquires a finite number of samples and you
set this input to nidaqmx.constants.READ_ALL_AVAILABLE,
the method waits for the task to acquire all requested
samples, then reads those samples. If you set the
"read_all_avail_samp" property to True, the method reads
the samples currently available in the buffer and does
not wait for the task to acquire all requested samples.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
int:
Indicates the number of samples acquired by each channel.
NI-DAQmx returns a single value because this value is the
same for all channels.
"""
number_of_samples_per_channel = (
self._task._calculate_num_samps_per_chan(
number_of_samples_per_channel))
self._verify_array(voltage_data, number_of_samples_per_channel, True, True)
self._verify_array(current_data, number_of_samples_per_channel, True, True)
_, _, samps_per_chan_read = self._interpreter.read_power_binary_i16(
self._handle, number_of_samples_per_channel, timeout,
FillMode.GROUP_BY_CHANNEL.value, voltage_data, current_data)
return samps_per_chan_read
[docs]
class CounterReader(ChannelReaderBase):
"""
Reads samples from a counter input channel in an NI-DAQmx task.
"""
[docs]
def read_many_sample_double(
self, data, number_of_samples_per_channel=READ_ALL_AVAILABLE,
timeout=10.0):
"""
Reads one or more floating-point samples from a single counter
input channel in a task.
This read method accepts a preallocated NumPy array to hold the
samples requested, which can be advantageous for performance and
interoperability with NumPy and SciPy.
Passing in a preallocated array is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
data (numpy.ndarray): Specifies a preallocated 1D NumPy
array of floating-point values to hold the samples
requested.
Each element in the array corresponds to a sample from
the channel. The size of the array must be large enough
to hold all requested samples from the channel in the
task; otherwise, an error is thrown.
number_of_samples_per_channel (Optional[int]): Specifies the
number of samples to read.
If you set this input to nidaqmx.constants.
READ_ALL_AVAILABLE, NI-DAQmx determines how many samples
to read based on if the task acquires samples
continuously or acquires a finite number of samples.
If the task acquires samples continuously and you set
this input to nidaqmx.constants.READ_ALL_AVAILABLE, this
method reads all the samples currently available in the
buffer.
If the task acquires a finite number of samples and you
set this input to nidaqmx.constants.READ_ALL_AVAILABLE,
the method waits for the task to acquire all requested
samples, then reads those samples. If you set the
"read_all_avail_samp" property to True, the method reads
the samples currently available in the buffer and does
not wait for the task to acquire all requested samples.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
int:
Indicates the number of samples acquired by each channel.
NI-DAQmx returns a single value because this value is the
same for all channels.
"""
number_of_samples_per_channel = (
self._task._calculate_num_samps_per_chan(
number_of_samples_per_channel))
self._verify_array(data, number_of_samples_per_channel, False, True)
_, samps_per_chan_read = self._interpreter.read_counter_f64_ex(
self._handle,number_of_samples_per_channel, timeout,
FillMode.GROUP_BY_CHANNEL.value, data)
return samps_per_chan_read
[docs]
def read_many_sample_pulse_frequency(
self, frequencies, duty_cycles,
number_of_samples_per_channel=READ_ALL_AVAILABLE, timeout=10.0):
"""
Reads one or more pulse samples in terms of frequency from a
single counter input channel in a task.
This read method accepts preallocated NumPy arrays to hold the
samples requested, which can be advantageous for performance and
interoperability with NumPy and SciPy.
Passing in preallocated arrays is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
frequencies (numpy.ndarray): Specifies a preallocated 1D
NumPy array of floating-point values to hold the frequency
portion of the pulse samples requested.
Each element in the array corresponds to a sample from
the channel. The size of the array must be large enough
to hold all requested samples from the channel in the
task; otherwise, an error is thrown.
duty_cycles (numpy.ndarray): Specifies a preallocated 1D
NumPy array of floating-point values to hold the duty
cycle portion of the pulse samples requested.
Each element in the array corresponds to a sample from
the channel. The size of the array must be large enough
to hold all requested samples from the channel in the
task; otherwise, an error is thrown.
number_of_samples_per_channel (Optional[int]): Specifies the
number of samples to read.
If you set this input to nidaqmx.constants.
READ_ALL_AVAILABLE, NI-DAQmx determines how many samples
to read based on if the task acquires samples
continuously or acquires a finite number of samples.
If the task acquires samples continuously and you set
this input to nidaqmx.constants.READ_ALL_AVAILABLE, this
method reads all the samples currently available in the
buffer.
If the task acquires a finite number of samples and you
set this input to nidaqmx.constants.READ_ALL_AVAILABLE,
the method waits for the task to acquire all requested
samples, then reads those samples. If you set the
"read_all_avail_samp" property to True, the method reads
the samples currently available in the buffer and does
not wait for the task to acquire all requested samples.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
int:
Indicates the number of samples acquired by each channel.
NI-DAQmx returns a single value because this value is the
same for all channels.
"""
number_of_samples_per_channel = (
self._task._calculate_num_samps_per_chan(
number_of_samples_per_channel))
self._verify_array(
frequencies, number_of_samples_per_channel, False, True)
self._verify_array(
duty_cycles, number_of_samples_per_channel, False, True)
_, _, samps_per_chan_read = self._interpreter.read_ctr_freq(
self._handle, number_of_samples_per_channel, timeout,
FillMode.GROUP_BY_CHANNEL.value, frequencies, duty_cycles)
return samps_per_chan_read
[docs]
def read_many_sample_pulse_ticks(
self, high_ticks, low_ticks,
number_of_samples_per_channel=READ_ALL_AVAILABLE, timeout=10.0):
"""
Reads one or more pulse samples in terms of ticks from a single
counter input channel in a task.
This read method accepts preallocated NumPy arrays to hold the
samples requested, which can be advantageous for performance and
interoperability with NumPy and SciPy.
Passing in preallocated arrays is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
high_ticks (numpy.ndarray): Specifies a preallocated 1D
NumPy array of 32-bit unsigned integer values to hold
the high ticks portion of the pulse samples requested.
Each element in the array corresponds to a sample from
the channel. The size of the array must be large enough
to hold all requested samples from the channel in the
task; otherwise, an error is thrown.
low_ticks (numpy.ndarray): Specifies a preallocated 1D NumPy
array of 32-bit unsigned integer values to hold the low
ticks portion of the pulse samples requested.
Each element in the array corresponds to a sample from
the channel. The size of the array must be large enough
to hold all requested samples from the channel in the
task; otherwise, an error is thrown.
number_of_samples_per_channel (Optional[int]): Specifies the
number of samples to read.
If you set this input to nidaqmx.constants.
READ_ALL_AVAILABLE, NI-DAQmx determines how many samples
to read based on if the task acquires samples
continuously or acquires a finite number of samples.
If the task acquires samples continuously and you set
this input to nidaqmx.constants.READ_ALL_AVAILABLE, this
method reads all the samples currently available in the
buffer.
If the task acquires a finite number of samples and you
set this input to nidaqmx.constants.READ_ALL_AVAILABLE,
the method waits for the task to acquire all requested
samples, then reads those samples. If you set the
"read_all_avail_samp" property to True, the method reads
the samples currently available in the buffer and does
not wait for the task to acquire all requested samples.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
int:
Indicates the number of samples acquired by each channel.
NI-DAQmx returns a single value because this value is the
same for all channels.
"""
number_of_samples_per_channel = (
self._task._calculate_num_samps_per_chan(
number_of_samples_per_channel))
self._verify_array(
high_ticks, number_of_samples_per_channel, False, True)
self._verify_array(
low_ticks, number_of_samples_per_channel, False, True)
_, _, samps_per_chan_read = self._interpreter.read_ctr_ticks(
self._handle, number_of_samples_per_channel, timeout,
FillMode.GROUP_BY_CHANNEL.value, high_ticks, low_ticks)
return samps_per_chan_read
[docs]
def read_many_sample_pulse_time(
self, high_times, low_times,
number_of_samples_per_channel=READ_ALL_AVAILABLE, timeout=10.0):
"""
Reads one or more pulse samples in terms of time from a single
counter input channel in a task.
This read method accepts preallocated NumPy arrays to hold the
samples requested, which can be advantageous for performance and
interoperability with NumPy and SciPy.
Passing in preallocated arrays is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
high_times (numpy.ndarray): Specifies a preallocated 1D
NumPy array of floating-point values to hold the high
time portion of the pulse samples requested.
Each element in the array corresponds to a sample from
the channel. The size of the array must be large enough
to hold all requested samples from the channel in the
task; otherwise, an error is thrown.
low_times (numpy.ndarray): Specifies a preallocated 1D
NumPy array of floating-point values to hold the low
time portion of the pulse samples requested.
Each element in the array corresponds to a sample from
the channel. The size of the array must be large enough
to hold all requested samples from the channel in the
task; otherwise, an error is thrown.
number_of_samples_per_channel (Optional[int]): Specifies the
number of samples to read.
If you set this input to nidaqmx.constants.
READ_ALL_AVAILABLE, NI-DAQmx determines how many samples
to read based on if the task acquires samples
continuously or acquires a finite number of samples.
If the task acquires samples continuously and you set
this input to nidaqmx.constants.READ_ALL_AVAILABLE, this
method reads all the samples currently available in the
buffer.
If the task acquires a finite number of samples and you
set this input to nidaqmx.constants.READ_ALL_AVAILABLE,
the method waits for the task to acquire all requested
samples, then reads those samples. If you set the
"read_all_avail_samp" property to True, the method reads
the samples currently available in the buffer and does
not wait for the task to acquire all requested samples.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
int:
Indicates the number of samples acquired by each channel.
NI-DAQmx returns a single value because this value is the
same for all channels.
"""
number_of_samples_per_channel = (
self._task._calculate_num_samps_per_chan(
number_of_samples_per_channel))
self._verify_array(
high_times, number_of_samples_per_channel, False, True)
self._verify_array(
low_times, number_of_samples_per_channel, False, True)
_, _, samps_per_chan_read = self._interpreter.read_ctr_time(
self._handle, number_of_samples_per_channel, timeout,
FillMode.GROUP_BY_CHANNEL.value, high_times, low_times)
return samps_per_chan_read
[docs]
def read_many_sample_uint32(
self, data, number_of_samples_per_channel=READ_ALL_AVAILABLE,
timeout=10.0):
"""
Reads one or more 32-bit unsigned integer samples from a single
counter input channel in a task.
This read method accepts a preallocated NumPy array to hold the
samples requested, which can be advantageous for performance and
interoperability with NumPy and SciPy.
Passing in a preallocated array is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
data (numpy.ndarray): Specifies a preallocated 1D NumPy
array of 32-bit unsigned integer values to hold the
samples requested.
Each element in the array corresponds to a sample from
the channel. The size of the array must be large enough
to hold all requested samples from the channel in the
task; otherwise, an error is thrown.
number_of_samples_per_channel (Optional[int]): Specifies the
number of samples to read.
If you set this input to nidaqmx.constants.
READ_ALL_AVAILABLE, NI-DAQmx determines how many samples
to read based on if the task acquires samples
continuously or acquires a finite number of samples.
If the task acquires samples continuously and you set
this input to nidaqmx.constants.READ_ALL_AVAILABLE, this
method reads all the samples currently available in the
buffer.
If the task acquires a finite number of samples and you
set this input to nidaqmx.constants.READ_ALL_AVAILABLE,
the method waits for the task to acquire all requested
samples, then reads those samples. If you set the
"read_all_avail_samp" property to True, the method reads
the samples currently available in the buffer and does
not wait for the task to acquire all requested samples.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
int:
Indicates the number of samples acquired by each channel.
NI-DAQmx returns a single value because this value is the
same for all channels.
"""
number_of_samples_per_channel = (
self._task._calculate_num_samps_per_chan(
number_of_samples_per_channel))
self._verify_array(data, number_of_samples_per_channel, False, True)
_, samps_per_chan_read = self._interpreter.read_counter_u32_ex(
self._handle, number_of_samples_per_channel, timeout,
FillMode.GROUP_BY_CHANNEL.value, data)
return samps_per_chan_read
[docs]
def read_one_sample_double(self, timeout=10):
"""
Reads a single floating-point sample from a single counter input
channel in a task.
Args:
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
float: Indicates a single floating-point sample from the
task.
"""
return self._interpreter.read_counter_scalar_f64(self._handle, timeout)
[docs]
def read_one_sample_pulse_frequency(self, timeout=10):
"""
Reads a pulse sample in terms of frequency from a single counter
input channel in a task.
Args:
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
nidaqmx.types.CtrFreq:
Indicates a pulse sample in terms of frequency from the task.
"""
freq, duty_cycle = self._interpreter.read_ctr_freq_scalar(self._handle, timeout)
return CtrFreq(freq, duty_cycle)
[docs]
def read_one_sample_pulse_ticks(self, timeout=10):
"""
Reads a pulse sample in terms of ticks from a single counter
input channel in a task.
Args:
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
nidaqmx.types.CtrTick:
Indicates a pulse sample in terms of ticks from the task.
"""
high_ticks, low_ticks = self._interpreter.read_ctr_ticks_scalar(self._handle, timeout)
return CtrTick(high_ticks, low_ticks)
[docs]
def read_one_sample_pulse_time(self, timeout=10):
"""
Reads a pulse sample in terms of time from a single counter
input channel in a task.
Args:
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
nidaqmx.types.CtrTime:
Indicates a pulse sample in terms of time from the task.
"""
high_time, low_time = self._interpreter.read_ctr_time_scalar(self._handle, timeout)
return CtrTime(high_time, low_time)
[docs]
def read_one_sample_uint32(self, timeout=10):
"""
Reads a single 32-bit unsigned integer sample from a single
counter input channel in a task.
Args:
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
int:
Indicates a single 32-bit unsigned integer sample from the
task.
"""
return self._interpreter.read_counter_scalar_u32(self._handle, timeout)
[docs]
class DigitalSingleChannelReader(ChannelReaderBase):
"""
Reads samples from a digital input channel in an NI-DAQmx task.
"""
[docs]
def read_many_sample_port_byte(
self, data, number_of_samples_per_channel=READ_ALL_AVAILABLE,
timeout=10.0):
"""
Reads one or more 8-bit unsigned integer samples from a single
digital input channel in a task.
Use this method for devices with up to 8 lines per port.
This read method accepts a preallocated NumPy array to hold
the samples requested, which can be advantageous for performance
and interoperability with NumPy and SciPy.
Passing in a preallocated array is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
data (numpy.ndarray): Specifies a preallocated 1D NumPy
array of 8-bit unsigned integer values to hold the
samples requested.
Each element in the array corresponds to a sample from
the channel. The size of the array must be large enough
to hold all requested samples from the channel in the
task; otherwise, an error is thrown.
number_of_samples_per_channel (Optional[int]): Specifies the
number of samples to read.
If you set this input to nidaqmx.constants.
READ_ALL_AVAILABLE, NI-DAQmx determines how many samples
to read based on if the task acquires samples
continuously or acquires a finite number of samples.
If the task acquires samples continuously and you set
this input to nidaqmx.constants.READ_ALL_AVAILABLE, this
method reads all the samples currently available in the
buffer.
If the task acquires a finite number of samples and you
set this input to nidaqmx.constants.READ_ALL_AVAILABLE,
the method waits for the task to acquire all requested
samples, then reads those samples. If you set the
"read_all_avail_samp" property to True, the method reads
the samples currently available in the buffer and does
not wait for the task to acquire all requested samples.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
int:
Indicates the number of samples acquired by each channel.
NI-DAQmx returns a single value because this value is the
same for all channels.
"""
number_of_samples_per_channel = (
self._task._calculate_num_samps_per_chan(
number_of_samples_per_channel))
self._verify_array(data, number_of_samples_per_channel, False, True)
_, samps_per_chan_read = self._interpreter.read_digital_u8(
self._handle, number_of_samples_per_channel, timeout,
FillMode.GROUP_BY_CHANNEL.value, data)
return samps_per_chan_read
[docs]
def read_many_sample_port_uint16(
self, data, number_of_samples_per_channel=READ_ALL_AVAILABLE,
timeout=10.0):
"""
Reads one or more 16-bit unsigned integer samples from a single
digital input channel in a task.
Use this method for devices with up to 16 lines per port.
This read method accepts a preallocated NumPy array to hold
the samples requested, which can be advantageous for performance
and interoperability with NumPy and SciPy.
Passing in a preallocated array is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
data (numpy.ndarray): Specifies a preallocated 1D NumPy
array of 16-bit unsigned integer values to hold the
samples requested.
Each element in the array corresponds to a sample from
the channel. The size of the array must be large enough
to hold all requested samples from the channel in the
task; otherwise, an error is thrown.
number_of_samples_per_channel (Optional[int]): Specifies the
number of samples to read.
If you set this input to nidaqmx.constants.
READ_ALL_AVAILABLE, NI-DAQmx determines how many samples
to read based on if the task acquires samples
continuously or acquires a finite number of samples.
If the task acquires samples continuously and you set
this input to nidaqmx.constants.READ_ALL_AVAILABLE, this
method reads all the samples currently available in the
buffer.
If the task acquires a finite number of samples and you
set this input to nidaqmx.constants.READ_ALL_AVAILABLE,
the method waits for the task to acquire all requested
samples, then reads those samples. If you set the
"read_all_avail_samp" property to True, the method reads
the samples currently available in the buffer and does
not wait for the task to acquire all requested samples.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
int:
Indicates the number of samples acquired by each channel.
NI-DAQmx returns a single value because this value is the
same for all channels.
"""
number_of_samples_per_channel = (
self._task._calculate_num_samps_per_chan(
number_of_samples_per_channel))
self._verify_array(data, number_of_samples_per_channel, False, True)
_, samps_per_chan_read = self._interpreter.read_digital_u16(
self._handle, number_of_samples_per_channel, timeout,
FillMode.GROUP_BY_CHANNEL.value, data)
return samps_per_chan_read
[docs]
def read_many_sample_port_uint32(
self, data, number_of_samples_per_channel=READ_ALL_AVAILABLE,
timeout=10.0):
"""
Reads one or more 32-bit unsigned integer samples from a single
digital input channel in a task.
Use this method for devices with up to 32 lines per port.
This read method accepts a preallocated NumPy array to hold
the samples requested, which can be advantageous for performance
and interoperability with NumPy and SciPy.
Passing in a preallocated array is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
data (numpy.ndarray): Specifies a preallocated 1D NumPy
array of 32-bit unsigned integer values to hold the
samples requested.
Each element in the array corresponds to a sample from
the channel. The size of the array must be large enough
to hold all requested samples from the channel in the
task; otherwise, an error is thrown.
number_of_samples_per_channel (Optional[int]): Specifies the
number of samples to read.
If you set this input to nidaqmx.constants.
READ_ALL_AVAILABLE, NI-DAQmx determines how many samples
to read based on if the task acquires samples
continuously or acquires a finite number of samples.
If the task acquires samples continuously and you set
this input to nidaqmx.constants.READ_ALL_AVAILABLE, this
method reads all the samples currently available in the
buffer.
If the task acquires a finite number of samples and you
set this input to nidaqmx.constants.READ_ALL_AVAILABLE,
the method waits for the task to acquire all requested
samples, then reads those samples. If you set the
"read_all_avail_samp" property to True, the method reads
the samples currently available in the buffer and does
not wait for the task to acquire all requested samples.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
int:
Indicates the number of samples acquired by each channel.
NI-DAQmx returns a single value because this value is the
same for all channels.
"""
number_of_samples_per_channel = (
self._task._calculate_num_samps_per_chan(
number_of_samples_per_channel))
self._verify_array(data, number_of_samples_per_channel, False, True)
_, samps_per_chan_read = self._interpreter.read_digital_u32(
self._handle, number_of_samples_per_channel, timeout,
FillMode.GROUP_BY_CHANNEL.value, data)
return samps_per_chan_read
[docs]
def read_one_sample_multi_line(self, data, timeout=10):
"""
Reads a single boolean sample from a single digital input
channel in a task. The channel can contain multiple digital
lines.
This read method accepts a preallocated NumPy array to hold the
samples requested, which can be advantageous for performance and
interoperability with NumPy and SciPy.
Passing in a preallocated array is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
data (numpy.ndarray): Specifies a preallocated 1D NumPy
array of boolean values to hold the samples requested.
Each element in the array corresponds to a sample from
a line in the channel. The size of the array must be
large enough to hold all requested samples from the
channel in the task; otherwise, an error is thrown.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
"""
self._verify_array_digital_lines(data, False, True)
_, samps_per_chan_read, num_bytes_per_samp = self._interpreter.read_digital_lines(
self._handle, 1, timeout, FillMode.GROUP_BY_CHANNEL.value, data)
[docs]
def read_one_sample_one_line(self, timeout=10):
"""
Reads a single boolean sample from a single digital input
channel in a task. The channel can contain only one digital
line.
Args:
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
bool:
Indicates a single boolean sample from the task.
"""
data = numpy.zeros(1, dtype=bool)
_, samps_per_chan_read, num_bytes_per_samp= self._interpreter.read_digital_lines(
self._handle, 1, timeout, FillMode.GROUP_BY_CHANNEL.value, data)
return bool(data[0])
[docs]
def read_one_sample_port_byte(self, timeout=10):
"""
Reads a single 8-bit unsigned integer sample from a single
digital input channel in a task.
Use this method for devices with up to 8 lines per port.
Args:
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
int:
Indicates a single 8-bit unsigned integer sample from the
task.
"""
data = numpy.zeros(1, dtype=numpy.uint8)
_, samps_per_chan_read = self._interpreter.read_digital_u8(
self._handle, 1, timeout, FillMode.GROUP_BY_CHANNEL.value, data)
return int(data[0])
[docs]
def read_one_sample_port_uint16(self, timeout=10):
"""
Reads a single 16-bit unsigned integer sample from a single
digital input channel in a task.
Use this method for devices with up to 16 lines per port.
Args:
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
int:
Indicates a single 16-bit unsigned integer sample from the
task.
"""
data = numpy.zeros(1, dtype=numpy.uint16)
_, samps_per_read_chan = self._interpreter.read_digital_u16(
self._handle, 1, timeout, FillMode.GROUP_BY_CHANNEL.value, data)
return int(data[0])
[docs]
def read_one_sample_port_uint32(self, timeout=10):
"""
Reads a single 32-bit unsigned integer sample from a single
digital input channel in a task.
Use this method for devices with up to 32 lines per port.
Args:
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
int:
Indicates a single 32-bit unsigned integer sample from the
task.
"""
return self._interpreter.read_digital_scalar_u32(self._handle, timeout)
[docs]
class DigitalMultiChannelReader(ChannelReaderBase):
"""
Reads samples from one or more digital input channels in an NI-DAQmx
task.
"""
[docs]
def read_many_sample_port_byte(
self, data, number_of_samples_per_channel=READ_ALL_AVAILABLE,
timeout=10.0):
"""
Reads one or more 8-bit unsigned integer samples from one or
more digital input channel in a task.
Use this method for devices with up to 8 lines per port.
This read method accepts a preallocated NumPy array to hold the
samples requested, which can be advantageous for performance and
interoperability with NumPy and SciPy.
Passing in a preallocated array is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
data (numpy.ndarray): Specifies a preallocated 2D NumPy
array of 8-bit unsigned integer values to hold the
samples requested. The size of the array must be large
enough to hold all requested samples from all channels
in the task; otherwise, an error is thrown.
Each row corresponds to a channel in the task. Each
column corresponds to a sample from each channel. The
order of the channels in the array corresponds to the
order in which you add the channels to the task or to
the order of the channels you specify with the
"channels_to_read" property.
If the size of the array is too large or the array is
shaped incorrectly, the previous statement may not hold
true as the samples read may not be separated into rows
and columns properly. Set the "verify_array_shape"
property on this channel reader object to True to
validate that the NumPy array object is shaped properly.
Setting this property may marginally adversely impact
the performance of the method.
number_of_samples_per_channel (Optional[int]): Specifies the
number of samples to read.
If you set this input to nidaqmx.constants.
READ_ALL_AVAILABLE, NI-DAQmx determines how many samples
to read based on if the task acquires samples
continuously or acquires a finite number of samples.
If the task acquires samples continuously and you set
this input to nidaqmx.constants.READ_ALL_AVAILABLE, this
method reads all the samples currently available in the
buffer.
If the task acquires a finite number of samples and you
set this input to nidaqmx.constants.READ_ALL_AVAILABLE,
the method waits for the task to acquire all requested
samples, then reads those samples. If you set the
"read_all_avail_samp" property to True, the method reads
the samples currently available in the buffer and does
not wait for the task to acquire all requested samples.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
int:
Indicates the number of samples acquired by each channel.
NI-DAQmx returns a single value because this value is the
same for all channels.
"""
number_of_samples_per_channel = (
self._task._calculate_num_samps_per_chan(
number_of_samples_per_channel))
self._verify_array(data, number_of_samples_per_channel, True, True)
_, samps_per_chan_read = self._interpreter.read_digital_u8(
self._handle, number_of_samples_per_channel, timeout,
FillMode.GROUP_BY_CHANNEL.value, data)
return samps_per_chan_read
[docs]
def read_many_sample_port_uint16(
self, data, number_of_samples_per_channel=READ_ALL_AVAILABLE,
timeout=10.0):
"""
Reads one or more 16-bit unsigned integer samples from one or
more digital input channels in a task.
Use this method for devices with up to 16 lines per port.
This read method accepts a preallocated NumPy array to hold the
samples requested, which can be advantageous for performance and
interoperability with NumPy and SciPy.
Passing in a preallocated array is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
data (numpy.ndarray): Specifies a preallocated 2D NumPy
array of 16-bit unsigned integer values to hold the
samples requested. The size of the array must be large
enough to hold all requested samples from all channels
in the task; otherwise, an error is thrown.
Each row corresponds to a channel in the task. Each
column corresponds to a sample from each channel. The
order of the channels in the array corresponds to the
order in which you add the channels to the task or to
the order of the channels you specify with the
"channels_to_read" property.
If the size of the array is too large or the array is
shaped incorrectly, the previous statement may not hold
true as the samples read may not be separated into rows
and columns properly. Set the "verify_array_shape"
property on this channel reader object to True to
validate that the NumPy array object is shaped properly.
Setting this property may marginally adversely impact
the performance of the method.
number_of_samples_per_channel (Optional[int]): Specifies the
number of samples to read.
If you set this input to nidaqmx.constants.
READ_ALL_AVAILABLE, NI-DAQmx determines how many samples
to read based on if the task acquires samples
continuously or acquires a finite number of samples.
If the task acquires samples continuously and you set
this input to nidaqmx.constants.READ_ALL_AVAILABLE, this
method reads all the samples currently available in the
buffer.
If the task acquires a finite number of samples and you
set this input to nidaqmx.constants.READ_ALL_AVAILABLE,
the method waits for the task to acquire all requested
samples, then reads those samples. If you set the
"read_all_avail_samp" property to True, the method reads
the samples currently available in the buffer and does
not wait for the task to acquire all requested samples.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
int:
Indicates the number of samples acquired by each channel.
NI-DAQmx returns a single value because this value is the
same for all channels.
"""
number_of_samples_per_channel = (
self._task._calculate_num_samps_per_chan(
number_of_samples_per_channel))
self._verify_array(data, number_of_samples_per_channel, True, True)
_, samps_per_chan_read = self._interpreter.read_digital_u16(
self._handle, number_of_samples_per_channel, timeout, FillMode.GROUP_BY_CHANNEL.value, data)
return samps_per_chan_read
[docs]
def read_many_sample_port_uint32(
self, data, number_of_samples_per_channel=READ_ALL_AVAILABLE,
timeout=10.0):
"""
Reads one or more 32-bit unsigned integer samples from one or
more digital input channels in a task.
Use this method for devices with up to 32 lines per port.
This read method accepts a preallocated NumPy array to hold the
samples requested, which can be advantageous for performance and
interoperability with NumPy and SciPy.
Passing in a preallocated array is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
data (numpy.ndarray): Specifies a preallocated 2D NumPy
array of 32-bit unsigned integer values to hold the
samples requested. The size of the array must be large
enough to hold all requested samples from all channels
in the task; otherwise, an error is thrown.
Each row corresponds to a channel in the task. Each
column corresponds to a sample from each channel. The
order of the channels in the array corresponds to the
order in which you add the channels to the task or to
the order of the channels you specify with the
"channels_to_read" property.
If the size of the array is too large or the array is
shaped incorrectly, the previous statement may not hold
true as the samples read may not be separated into rows
and columns properly. Set the "verify_array_shape"
property on this channel reader object to True to
validate that the NumPy array object is shaped properly.
Setting this property may marginally adversely impact
the performance of the method.
number_of_samples_per_channel (Optional[int]): Specifies the
number of samples to read.
If you set this input to nidaqmx.constants.
READ_ALL_AVAILABLE, NI-DAQmx determines how many samples
to read based on if the task acquires samples
continuously or acquires a finite number of samples.
If the task acquires samples continuously and you set
this input to nidaqmx.constants.READ_ALL_AVAILABLE, this
method reads all the samples currently available in the
buffer.
If the task acquires a finite number of samples and you
set this input to nidaqmx.constants.READ_ALL_AVAILABLE,
the method waits for the task to acquire all requested
samples, then reads those samples. If you set the
"read_all_avail_samp" property to True, the method reads
the samples currently available in the buffer and does
not wait for the task to acquire all requested samples.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
Returns:
int:
Indicates the number of samples acquired by each channel.
NI-DAQmx returns a single value because this value is the
same for all channels.
"""
number_of_samples_per_channel = (
self._task._calculate_num_samps_per_chan(
number_of_samples_per_channel))
self._verify_array(data, number_of_samples_per_channel, True, True)
_, samps_per_chan_read = self._interpreter.read_digital_u32(
self._handle, number_of_samples_per_channel, timeout, FillMode.GROUP_BY_CHANNEL.value, data)
return samps_per_chan_read
[docs]
def read_one_sample_multi_line(self, data, timeout=10):
"""
Reads a single boolean sample from one or more digital input
channels in a task. The channels can contain multiple digital
lines.
This read method accepts a preallocated NumPy array to hold the
samples requested, which can be advantageous for performance and
interoperability with NumPy and SciPy.
Passing in a preallocated array is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
data (numpy.ndarray): Specifies a preallocated 2D NumPy
array of boolean values to hold the samples requested.
The size of the array must be large enough to hold all
requested samples from all channels in the task;
otherwise, an error is thrown.
Each row corresponds to a channel in the task. Each
column corresponds to a line from each channel. The
order of the channels in the array corresponds to the
order in which you add the channels to the task or to
the order of the channels you specify with the
"channels_to_read" property.
If the size of the array is too large or the array is
shaped incorrectly, the previous statement may not hold
true as the samples read may not be separated into rows
and columns properly. Set the "verify_array_shape"
property on this channel reader object to True to
validate that the NumPy array object is shaped properly.
Setting this property may marginally adversely impact
the performance of the method.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
"""
self._verify_array_digital_lines(data, True, True)
_, samps_per_chan_read, num_bytes_per_samp= self._interpreter.read_digital_lines(
self._handle, 1, timeout, FillMode.GROUP_BY_CHANNEL.value, data)
[docs]
def read_one_sample_one_line(self, data, timeout=10):
"""
Reads a single boolean sample from one or more digital input
channels in a task. The channel can contain only one digital
line.
This read method accepts a preallocated NumPy array to hold the
samples requested, which can be advantageous for performance and
interoperability with NumPy and SciPy.
Passing in a preallocated array is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
data (numpy.ndarray): Specifies a preallocated 1D NumPy
array of boolean values to hold the samples requested.
Each element in the array corresponds to a sample from
each channel. The size of the array must be large enough
to hold all requested samples from the channel in the
task; otherwise, an error is thrown.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
"""
self._verify_array_digital_lines(data, True, False)
_, samps_per_chan_read, num_bytes_per_samp= self._interpreter.read_digital_lines(
self._handle, 1, timeout, FillMode.GROUP_BY_CHANNEL.value, data)
[docs]
def read_one_sample_port_byte(self, data, timeout=10):
"""
Reads a single 8-bit unsigned integer sample from one or more
digital input channels in a task.
Use this method for devices with up to 8 lines per port.
This read method accepts a preallocated NumPy array to hold the
samples requested, which can be advantageous for performance and
interoperability with NumPy and SciPy.
Passing in a preallocated array is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
data (numpy.ndarray): Specifies a preallocated 1D NumPy
array of 8-bit unsigned integer values to hold the
samples requested.
Each element in the array corresponds to a sample from
each channel. The size of the array must be large enough
to hold all requested samples from the channel in the
task; otherwise, an error is thrown.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
"""
self._verify_array(data, 1, True, False)
self._interpreter.read_digital_u8(
self._handle, 1, timeout, FillMode.GROUP_BY_CHANNEL.value, data)
[docs]
def read_one_sample_port_uint16(self, data, timeout=10):
"""
Reads a single 16-bit unsigned integer sample from one or more
digital input channels in a task.
Use this method for devices with up to 16 lines per port.
This read method accepts a preallocated NumPy array to hold the
samples requested, which can be advantageous for performance and
interoperability with NumPy and SciPy.
Passing in a preallocated array is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
data (numpy.ndarray): Specifies a preallocated 1D NumPy
array of 16-bit unsigned integer values to hold the
samples requested.
Each element in the array corresponds to a sample from
each channel. The size of the array must be large enough
to hold all requested samples from the channel in the
task; otherwise, an error is thrown.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
"""
self._verify_array(data, 1, True, False)
self._interpreter.read_digital_u16(
self._handle, 1, timeout, FillMode.GROUP_BY_CHANNEL.value, data)
[docs]
def read_one_sample_port_uint32(self, data, timeout=10):
"""
Reads a single 32-bit unsigned integer sample from one or more
digital input channels in a task.
Use this method for devices with up to 32 lines per port.
This read method accepts a preallocated NumPy array to hold the
samples requested, which can be advantageous for performance and
interoperability with NumPy and SciPy.
Passing in a preallocated array is valuable in continuous
acquisition scenarios, where the same array can be used
repeatedly in each call to the method.
Args:
data (numpy.ndarray): Specifies a preallocated 1D NumPy
array of 32-bit unsigned integer values to hold the
samples requested.
Each element in the array corresponds to a sample from
each channel. The size of the array must be large enough
to hold all requested samples from the channel in the
task; otherwise, an error is thrown.
timeout (Optional[float]): Specifies the amount of time in
seconds to wait for samples to become available. If the
time elapses, the method returns an error and any
samples read before the timeout elapsed. The default
timeout is 10 seconds. If you set timeout to
nidaqmx.constants.WAIT_INFINITELY, the method waits
indefinitely. If you set timeout to 0, the method tries
once to read the requested samples and returns an error
if it is unable to.
"""
self._verify_array(data, 1, True, False)
self._interpreter.read_digital_u32(
self._handle, 1, timeout, FillMode.GROUP_BY_CHANNEL.value, data)