Skip to content

Commit 31fe4d7

Browse files
mikeprosserniMike Prosser
andauthored
Add support for read_waveform(READ_ALL_AVAILABLE) (#881)
* fix preexisting mypy issue * support for number_of_samples_per_channel=READ_ALL_AVAILABLE * update GetDefaultNumberOfSamplesToRead to be CustomCode * lint * use DAQmx_DefaultNumberOfSamplesToRead instead of get_default_number_of_samples_to_read() * cleanup * check self._interpreter.driver_version >= (24, 8) * cache the error if DAQmx_DefaultNumberOfSamplesToRead is unavailable * remove try/except and _default_number_of_samples_attribute_available * DriverVersion improvements * cleanup * enable new grpc tests * update nidaqmx.proto * revert nidaqmx.proto --------- Co-authored-by: Mike Prosser <[email protected]>
1 parent ebd61c2 commit 31fe4d7

20 files changed

+252
-32
lines changed

generated/nidaqmx/_base_interpreter.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,6 +1858,11 @@ def write_to_teds_from_file(
18581858
def hash_task_handle(self, task_handle):
18591859
raise NotImplementedError
18601860

1861+
@property
1862+
@abc.abstractmethod
1863+
def driver_version(self):
1864+
raise NotImplementedError
1865+
18611866
@abc.abstractmethod
18621867
def read_analog_waveform(
18631868
self,

generated/nidaqmx/_grpc_interpreter.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
)
2727
from nidaqmx.constants import WaveformAttributeMode
2828
from nidaqmx.error_codes import DAQmxErrors
29+
from nidaqmx.types import DriverVersion
2930
from nidaqmx._grpc_time import convert_time_to_timestamp, convert_timestamp_to_time
3031
from nidaqmx._waveform_utils import get_num_samps_per_chan
3132
from session_pb2 import Session
@@ -94,11 +95,21 @@ class GrpcStubInterpreter(BaseInterpreter):
9495
__slots__ = [
9596
'_grpc_options',
9697
'_client',
98+
'_driver_version',
9799
]
98100

99101
def __init__(self, grpc_options):
100102
self._grpc_options = grpc_options
101103
self._client = nidaqmx_grpc.NiDAQmxStub(grpc_options.grpc_channel)
104+
try:
105+
major_version = self.get_system_info_attribute_uint32(0x1272)
106+
minor_version = self.get_system_info_attribute_uint32(0x1923)
107+
update_version = self.get_system_info_attribute_uint32(0x2f22)
108+
except Exception:
109+
major_version = 0
110+
minor_version = 0
111+
update_version = 0
112+
self._driver_version = DriverVersion(major_version, minor_version, update_version)
102113

103114
def _invoke(self, func, request, metadata=None):
104115
try:
@@ -177,6 +188,10 @@ def _check_for_event_registration_error(self, event_stream):
177188
except grpc.RpcError as rpc_error:
178189
self._handle_rpc_error(rpc_error)
179190

191+
@property
192+
def driver_version(self):
193+
return self._driver_version
194+
180195
def add_cdaq_sync_connection(self, port_list):
181196
response = self._invoke(
182197
self._client.AddCDAQSyncConnection,

generated/nidaqmx/_library_interpreter.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from nidaqmx.constants import FillMode, WaveformAttributeMode
2020
from nidaqmx.error_codes import DAQmxErrors, DAQmxWarnings
2121
from nidaqmx.errors import DaqError, DaqFunctionNotSupportedError, DaqReadError, DaqWarning, DaqWriteError
22+
from nidaqmx.types import DriverVersion
2223
from nidaqmx._lib_time import AbsoluteTime
2324
from nidaqmx._waveform_utils import get_num_samps_per_chan
2425
from nitypes.waveform.typing import ExtendedPropertyValue
@@ -74,7 +75,7 @@ class LibraryInterpreter(BaseInterpreter):
7475
7576
"""
7677
# Do not add per-task state to the interpreter class.
77-
__slots__ = ()
78+
__slots__ = ('_driver_version',)
7879

7980
def __init__(self):
8081
global _was_runtime_environment_set
@@ -93,6 +94,15 @@ def __init__(self):
9394
finally:
9495
_was_runtime_environment_set = True
9596

97+
major_version = self.get_system_info_attribute_uint32(0x1272)
98+
minor_version = self.get_system_info_attribute_uint32(0x1923)
99+
update_version = self.get_system_info_attribute_uint32(0x2f22)
100+
self._driver_version = DriverVersion(major_version, minor_version, update_version)
101+
102+
@property
103+
def driver_version(self):
104+
return self._driver_version
105+
96106

97107
def add_cdaq_sync_connection(self, port_list):
98108
cfunc = lib_importer.windll.DAQmxAddCDAQSyncConnection

generated/nidaqmx/stream_readers/_digital_multi_channel_reader.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ def read_waveforms(
493493
number_of_samples_per_channel: int = READ_ALL_AVAILABLE,
494494
reallocation_policy: ReallocationPolicy = ReallocationPolicy.TO_GROW,
495495
timeout: float = 10.0,
496-
) -> list[DigitalWaveform[Any]]:
496+
) -> int:
497497
"""Reads one or more samples from one or more digital input channels into a list of waveforms.
498498
499499
Args:
@@ -568,7 +568,7 @@ def read_waveforms(
568568
task_name=self._task.name,
569569
)
570570

571-
waveforms = self._interpreter.read_digital_waveforms(
571+
return self._interpreter.read_digital_waveforms(
572572
self._handle,
573573
number_of_channels,
574574
number_of_samples_per_channel,
@@ -577,5 +577,3 @@ def read_waveforms(
577577
waveforms,
578578
self._in_stream.waveform_attribute_mode,
579579
)
580-
581-
return waveforms

generated/nidaqmx/system/system.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import ctypes
55
import deprecation
66
import numpy
7+
import typing
78

89
from nidaqmx import utils
910
from nidaqmx.system._collections.device_collection import DeviceCollection
@@ -19,6 +20,7 @@
1920
SignalModifiers, WAIT_INFINITELY)
2021
from nidaqmx.types import (
2122
AOPowerUpState, CDAQSyncConnection, DOPowerUpState, DOResistorPowerUpState)
23+
import nidaqmx.types
2224
from nidaqmx.system.device import _DeviceAlternateConstructor
2325

2426
__all__ = ['System']
@@ -70,9 +72,7 @@ def devices(self):
7072
return DeviceCollection(self._interpreter)
7173

7274

73-
DriverVersion = collections.namedtuple(
74-
'DriverVersion', ['major_version', 'minor_version',
75-
'update_version'])
75+
DriverVersion: typing.TypeAlias = nidaqmx.types.DriverVersion
7676

7777
@property
7878
def driver_version(self):
@@ -87,8 +87,8 @@ def driver_version(self):
8787
- update_version (int): Indicates the update portion of the
8888
installed version of NI-DAQmx, such as 1 for version 9.0.1.
8989
"""
90-
return System.DriverVersion(self._major_version, self._minor_version,
91-
self._update_version)
90+
return nidaqmx.types.DriverVersion(self._major_version, self._minor_version,
91+
self._update_version)
9292

9393
@property
9494
def global_channels(self):

generated/nidaqmx/task/_task.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,16 @@ def _calculate_num_samps_per_chan(self, num_samps_per_chan):
294294
if num_samps_per_chan is NUM_SAMPLES_UNSET:
295295
return 1
296296
elif num_samps_per_chan == READ_ALL_AVAILABLE:
297-
acq_type = self.timing.samp_quant_samp_mode
298-
299-
if acq_type == AcquisitionType.FINITE and not self.in_stream.read_all_avail_samp:
300-
return self.timing.samp_quant_samp_per_chan
297+
if self._interpreter.driver_version >= (24, 5):
298+
# DAQmx_DefaultNumberOfSamplesToRead is 0x31E8
299+
return self._interpreter.get_read_attribute_uint32(self._handle, 0x31E8)
301300
else:
302-
return self.in_stream.avail_samp_per_chan
301+
acq_type = self.timing.samp_quant_samp_mode
302+
303+
if acq_type == AcquisitionType.FINITE and not self.in_stream.read_all_avail_samp:
304+
return self.timing.samp_quant_samp_per_chan
305+
else:
306+
return self.in_stream.avail_samp_per_chan
303307
else:
304308
return num_samps_per_chan
305309

generated/nidaqmx/types.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353

5454
CDAQSyncConnection = collections.namedtuple("CDAQSyncConnection", ["output_port", "input_port"])
5555

56+
DriverVersion = collections.namedtuple(
57+
"DriverVersion", ["major_version", "minor_version", "update_version"]
58+
)
59+
5660
# endregion
5761

5862
# region ID Pin namedtuples

src/codegen/templates/_base_interpreter.py.mako

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ class BaseInterpreter(abc.ABC):
6363
def hash_task_handle(self, task_handle):
6464
raise NotImplementedError
6565

66+
@property
67+
@abc.abstractmethod
68+
def driver_version(self):
69+
raise NotImplementedError
70+
6671
@abc.abstractmethod
6772
def read_analog_waveform(
6873
self,

src/codegen/templates/_grpc_interpreter.py.mako

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ from ni.protobuf.types.waveform_conversion import (
4343
)
4444
from nidaqmx.constants import WaveformAttributeMode
4545
from nidaqmx.error_codes import DAQmxErrors
46+
from nidaqmx.types import DriverVersion
4647
from nidaqmx._grpc_time import convert_time_to_timestamp, convert_timestamp_to_time
4748
from nidaqmx._waveform_utils import get_num_samps_per_chan
4849
from session_pb2 import Session
@@ -111,11 +112,21 @@ class GrpcStubInterpreter(BaseInterpreter):
111112
__slots__ = [
112113
'_grpc_options',
113114
'_client',
115+
'_driver_version',
114116
]
115117

116118
def __init__(self, grpc_options):
117119
self._grpc_options = grpc_options
118120
self._client = nidaqmx_grpc.NiDAQmxStub(grpc_options.grpc_channel)
121+
try:
122+
major_version = self.get_system_info_attribute_uint32(0x1272)
123+
minor_version = self.get_system_info_attribute_uint32(0x1923)
124+
update_version = self.get_system_info_attribute_uint32(0x2f22)
125+
except Exception:
126+
major_version = 0
127+
minor_version = 0
128+
update_version = 0
129+
self._driver_version = DriverVersion(major_version, minor_version, update_version)
119130

120131
def _invoke(self, func, request, metadata=None):
121132
try:
@@ -194,6 +205,10 @@ class GrpcStubInterpreter(BaseInterpreter):
194205
except grpc.RpcError as rpc_error:
195206
self._handle_rpc_error(rpc_error)
196207

208+
@property
209+
def driver_version(self):
210+
return self._driver_version
211+
197212
%for func in functions:
198213
<%
199214
if func.function_name in GRPC_INTERPRETER_IGNORED_FUNCTIONS:

src/codegen/templates/_library_interpreter.py.mako

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ from nidaqmx._lib import lib_importer, ctypes_byte_str, c_bool32, wrapped_ndpoin
3636
from nidaqmx.constants import FillMode, WaveformAttributeMode
3737
from nidaqmx.error_codes import DAQmxErrors, DAQmxWarnings
3838
from nidaqmx.errors import DaqError, DaqFunctionNotSupportedError, DaqReadError, DaqWarning, DaqWriteError
39+
from nidaqmx.types import DriverVersion
3940
from nidaqmx._lib_time import AbsoluteTime
4041
from nidaqmx._waveform_utils import get_num_samps_per_chan
4142
from nitypes.waveform.typing import ExtendedPropertyValue
@@ -91,7 +92,7 @@ class LibraryInterpreter(BaseInterpreter):
9192

9293
"""
9394
# Do not add per-task state to the interpreter class.
94-
__slots__ = ()
95+
__slots__ = ('_driver_version',)
9596

9697
def __init__(self):
9798
global _was_runtime_environment_set
@@ -110,6 +111,15 @@ class LibraryInterpreter(BaseInterpreter):
110111
finally:
111112
_was_runtime_environment_set = True
112113

114+
major_version = self.get_system_info_attribute_uint32(0x1272)
115+
minor_version = self.get_system_info_attribute_uint32(0x1923)
116+
update_version = self.get_system_info_attribute_uint32(0x2f22)
117+
self._driver_version = DriverVersion(major_version, minor_version, update_version)
118+
119+
@property
120+
def driver_version(self):
121+
return self._driver_version
122+
113123

114124
% for func in functions:
115125
<%

0 commit comments

Comments
 (0)