Skip to content

Commit 5ab6d24

Browse files
authored
Adding new ID Pin API introduced in mioDAQ (#677)
* Update source files Signed-off-by: Jun Ying Tan <[email protected]> * Run codegen Signed-off-by: Jun Ying Tan <[email protected]> * Add tests Signed-off-by: Jun Ying Tan <[email protected]> * Update CHANGELOG.md Signed-off-by: Jun Ying Tan <[email protected]> * Fix hardcoded error message test failure Signed-off-by: Jun Ying Tan <[email protected]> --------- Signed-off-by: Jun Ying Tan <[email protected]>
1 parent fcddb56 commit 5ab6d24

32 files changed

+13681
-4862
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ All notable changes to this project will be documented in this file.
3131

3232
* ### Major Changes
3333
* Added support for mioDAQ configurable digital voltage.
34+
* Added support for mioDAQ ID Pin.
3435
* Removed support for Python 3.8.
3536

3637
* ### Known Issues

generated/nidaqmx/_base_interpreter.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,10 @@ def read_digital_u8(
13101310
self, task, num_samps_per_chan, timeout, fill_mode, read_array):
13111311
raise NotImplementedError
13121312

1313+
@abc.abstractmethod
1314+
def read_id_pin_memory(self, device_name, id_pin_name):
1315+
raise NotImplementedError
1316+
13131317
@abc.abstractmethod
13141318
def read_power_binary_i16(
13151319
self, task, num_samps_per_chan, timeout, fill_mode,
@@ -1817,6 +1821,10 @@ def write_digital_u8(
18171821
write_array):
18181822
raise NotImplementedError
18191823

1824+
@abc.abstractmethod
1825+
def write_id_pin_memory(self, device_name, id_pin_name, data, format_code):
1826+
raise NotImplementedError
1827+
18201828
@abc.abstractmethod
18211829
def write_raw(self, task, num_samps, auto_start, timeout, write_array):
18221830
raise NotImplementedError

generated/nidaqmx/_grpc_interpreter.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3533,6 +3533,13 @@ def write_digital_u8(
35333533
write_array=write_array.tobytes()))
35343534
return response.samps_per_chan_written
35353535

3536+
def write_id_pin_memory(self, device_name, id_pin_name, data, format_code):
3537+
response = self._invoke(
3538+
self._client.WriteIDPinMemory,
3539+
grpc_types.WriteIDPinMemoryRequest(
3540+
device_name=device_name, id_pin_name=id_pin_name,
3541+
data=data.tobytes(), format_code=format_code))
3542+
35363543
def write_raw(self, task, num_samps, auto_start, timeout, write_array):
35373544
_validate_array_dtype(write_array, numpy.generic)
35383545
response = self._invoke(
@@ -3574,6 +3581,18 @@ def get_error_string(self, error_code):
35743581
_logger.exception('Failed to get error string for error code %d.', error_code)
35753582
return 'Failed to retrieve error description.'
35763583

3584+
def read_id_pin_memory(self, device_name, id_pin_name):
3585+
response = self._invoke(
3586+
self._client.ReadIDPinMemory,
3587+
grpc_types.ReadIDPinMemoryRequest(device_name=device_name, id_pin_name=id_pin_name, array_size=0))
3588+
if response.status <= 0:
3589+
self._check_for_error_from_response(response.status)
3590+
response = self._invoke(
3591+
self._client.ReadIDPinMemory,
3592+
grpc_types.ReadIDPinMemoryRequest(device_name=device_name, id_pin_name=id_pin_name, array_size=response.status))
3593+
self._check_for_error_from_response(response.status)
3594+
return list(response.data), response.data_length_read, response.format_code
3595+
35773596
def set_runtime_environment(
35783597
self, environment, environment_version, reserved_1, reserved_2):
35793598
raise NotImplementedError
@@ -3607,5 +3626,5 @@ def _is_cancelled(ex: Exception) -> bool:
36073626
)
36083627

36093628
_ERROR_MESSAGES = {
3610-
DAQmxErrors.SAMPLES_NOT_YET_AVAILABLE: 'Some or all of the samples requested have not yet been acquired.\nTo wait for the samples to become available use a longer read timeout or read later in your program. To make the samples available sooner, increase the sample rate. If your task uses a start trigger, make sure that your start trigger is configured correctly. It is also possible that you configured the task for external timing, and no clock was supplied. If this is the case, supply an external clock.'
3611-
}
3629+
DAQmxErrors.SAMPLES_NOT_YET_AVAILABLE: 'Some or all of the samples requested have not yet been acquired.\n\nTo wait for the samples to become available use a longer read timeout or read later in your program. To make the samples available sooner, increase the sample rate. If your task uses a start trigger, make sure that your start trigger is configured correctly. It is also possible that you configured the task for external timing, and no clock was supplied. If this is the case, supply an external clock.'
3630+
}

generated/nidaqmx/_library_interpreter.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class LibraryInterpreter(BaseInterpreter):
4545
__slots__ = ()
4646

4747
def __init__(self):
48-
global _was_runtime_environment_set
48+
global _was_runtime_environment_set
4949
if _was_runtime_environment_set is None:
5050
try:
5151
runtime_env = platform.python_implementation()
@@ -6242,6 +6242,20 @@ def write_digital_u8(
62426242
self.check_for_error(error_code, samps_per_chan_written=samps_per_chan_written.value)
62436243
return samps_per_chan_written.value
62446244

6245+
def write_id_pin_memory(self, device_name, id_pin_name, data, format_code):
6246+
cfunc = lib_importer.windll.DAQmxWriteIDPinMemory
6247+
if cfunc.argtypes is None:
6248+
with cfunc.arglock:
6249+
if cfunc.argtypes is None:
6250+
cfunc.argtypes = [
6251+
ctypes_byte_str, ctypes_byte_str,
6252+
wrapped_ndpointer(dtype=numpy.uint8, flags=('C')),
6253+
ctypes.c_uint, ctypes.c_uint]
6254+
6255+
error_code = cfunc(
6256+
device_name, id_pin_name, data, len(data), format_code)
6257+
self.check_for_error(error_code)
6258+
62456259
def write_to_teds_from_array(
62466260
self, physical_channel, bit_stream, basic_teds_options):
62476261
cfunc = lib_importer.windll.DAQmxWriteToTEDSFromArray
@@ -6300,6 +6314,35 @@ def get_extended_error_info(self):
63006314
return 'Failed to retrieve error description.'
63016315
return error_buffer.value.decode(lib_importer.encoding)
63026316

6317+
def read_id_pin_memory(self, device_name, id_pin_name):
6318+
data_length_read = ctypes.c_uint()
6319+
format_code = ctypes.c_uint()
6320+
6321+
cfunc = lib_importer.windll.DAQmxReadIDPinMemory
6322+
if cfunc.argtypes is None:
6323+
with cfunc.arglock:
6324+
if cfunc.argtypes is None:
6325+
cfunc.argtypes = [
6326+
ctypes_byte_str, ctypes_byte_str,
6327+
wrapped_ndpointer(dtype=numpy.uint8, flags=('C','W')),
6328+
ctypes.c_uint, ctypes.POINTER(ctypes.c_uint),
6329+
ctypes.POINTER(ctypes.c_uint)]
6330+
6331+
array_size = cfunc(
6332+
device_name, id_pin_name, None, 0,
6333+
ctypes.byref(data_length_read), ctypes.byref(format_code))
6334+
6335+
if array_size < 0:
6336+
self.check_for_error(array_size)
6337+
6338+
data = numpy.zeros(array_size, dtype=numpy.uint8)
6339+
6340+
error_code = cfunc(
6341+
device_name, id_pin_name, data, array_size,
6342+
ctypes.byref(data_length_read), ctypes.byref(format_code))
6343+
self.check_for_error(error_code)
6344+
return data.tolist(), data_length_read.value, format_code.value
6345+
63036346
def read_power_binary_i16(
63046347
self, task, num_samps_per_chan, timeout, fill_mode,
63056348
read_voltage_array, read_current_array):
@@ -6424,4 +6467,4 @@ def is_string_buffer_too_small(error_code):
64246467

64256468

64266469
def is_array_buffer_too_small(error_code):
6427-
return error_code == DAQmxErrors.WRITE_BUFFER_TOO_SMALL
6470+
return error_code == DAQmxErrors.WRITE_BUFFER_TOO_SMALL

generated/nidaqmx/_stubs/data_moniker_pb2.py

Lines changed: 49 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)