From 232b41a846a9730d5cc27a456d878efae56fb41d Mon Sep 17 00:00:00 2001 From: DeborahOoi96 Date: Wed, 31 Jan 2024 14:45:48 +0800 Subject: [PATCH] Add support for WaitForValidTimestamp to nidaqmx-python --- generated/nidaqmx/_base_interpreter.py | 4 ++++ generated/nidaqmx/_grpc_interpreter.py | 8 ++++++++ generated/nidaqmx/_library_interpreter.py | 18 ++++++++++++++++++ src/codegen/metadata/functions.py | 12 +++++++++--- .../templates/_library_interpreter.py.mako | 1 + src/codegen/utilities/function_helpers.py | 6 ++++++ src/codegen/utilities/interpreter_helpers.py | 7 ++++++- 7 files changed, 52 insertions(+), 4 deletions(-) diff --git a/generated/nidaqmx/_base_interpreter.py b/generated/nidaqmx/_base_interpreter.py index 3cd868940..938c22a42 100644 --- a/generated/nidaqmx/_base_interpreter.py +++ b/generated/nidaqmx/_base_interpreter.py @@ -1649,6 +1649,10 @@ def unregister_signal_event(self, task, signal_id): def unreserve_network_device(self, device_name): raise NotImplementedError + @abc.abstractmethod + def wait_for_valid_timestamp(self, task, timestamp_event, timeout): + raise NotImplementedError + @abc.abstractmethod def wait_until_task_done(self, task, time_to_wait): raise NotImplementedError diff --git a/generated/nidaqmx/_grpc_interpreter.py b/generated/nidaqmx/_grpc_interpreter.py index 1ef808a83..c85ee6af1 100644 --- a/generated/nidaqmx/_grpc_interpreter.py +++ b/generated/nidaqmx/_grpc_interpreter.py @@ -3233,6 +3233,14 @@ def unreserve_network_device(self, device_name): self._client.UnreserveNetworkDevice, grpc_types.UnreserveNetworkDeviceRequest(device_name=device_name)) + def wait_for_valid_timestamp(self, task, timestamp_event, timeout): + response = self._invoke( + self._client.WaitForValidTimestamp, + grpc_types.WaitForValidTimestampRequest( + task=task, timestamp_event_raw=timestamp_event, + timeout=timeout)) + return response.timestamp + def wait_until_task_done(self, task, time_to_wait): response = self._invoke( self._client.WaitUntilTaskDone, diff --git a/generated/nidaqmx/_library_interpreter.py b/generated/nidaqmx/_library_interpreter.py index aa4cc075c..25a17dc46 100644 --- a/generated/nidaqmx/_library_interpreter.py +++ b/generated/nidaqmx/_library_interpreter.py @@ -12,6 +12,7 @@ from nidaqmx._lib import lib_importer, ctypes_byte_str, c_bool32, wrapped_ndpointer from nidaqmx.error_codes import DAQmxErrors, DAQmxWarnings from nidaqmx.errors import DaqError, DaqReadError, DaqWarning, DaqWriteError +from nidaqmx._lib_time import AbsoluteTime _logger = logging.getLogger(__name__) @@ -5596,6 +5597,23 @@ def unreserve_network_device(self, device_name): device_name) self.check_for_error(error_code) + def wait_for_valid_timestamp(self, task, timestamp_event, timeout): + timestamp = _lib_time.AbsoluteTime() + + cfunc = lib_importer.windll.DAQmxWaitForValidTimestamp + if cfunc.argtypes is None: + with cfunc.arglock: + if cfunc.argtypes is None: + cfunc.argtypes = [ + lib_importer.task_handle, ctypes.c_int32, + ctypes.c_double, + ctypes.POINTER(_lib_time.AbsoluteTime)] + + error_code = cfunc( + task, timestamp_event, timeout, ctypes.byref(timestamp)) + self.check_for_error(error_code) + return timestamp.value + def wait_until_task_done(self, task, time_to_wait): cfunc = lib_importer.windll.DAQmxWaitUntilTaskDone if cfunc.argtypes is None: diff --git a/src/codegen/metadata/functions.py b/src/codegen/metadata/functions.py index 6b4e47130..527c7159f 100644 --- a/src/codegen/metadata/functions.py +++ b/src/codegen/metadata/functions.py @@ -23601,6 +23601,11 @@ }, 'WaitForValidTimestamp': { 'calling_convention': 'StdCall', + 'handle_parameter': { + 'ctypes_data_type': 'lib_importer.task_handle', + 'cvi_name': 'taskHandle', + 'python_accessor': 'self._handle' + }, 'parameters': [ { 'ctypes_data_type': 'ctypes.TaskHandle', @@ -23639,13 +23644,14 @@ 'direction': 'out', 'is_optional_in_python': False, 'name': 'timestamp', - 'python_data_type': 'DateTime', + 'python_data_type': 'datetime', 'python_description': 'Specifies the timestamp type to wait on.', - 'python_type_annotation': 'nidaqmx.constants.DateTime', + 'python_type_annotation': 'datetime', 'type': 'CVIAbsoluteTime' } ], - 'python_codegen_method': 'no', + 'python_class_name': 'Task', + 'python_codegen_method': 'CustomCode', 'python_description': 'DAQmx Wait for Valid Timestamp', 'returns': 'int32' }, diff --git a/src/codegen/templates/_library_interpreter.py.mako b/src/codegen/templates/_library_interpreter.py.mako index d0ba335f2..f53465543 100644 --- a/src/codegen/templates/_library_interpreter.py.mako +++ b/src/codegen/templates/_library_interpreter.py.mako @@ -28,6 +28,7 @@ from nidaqmx._base_interpreter import BaseEventHandler, BaseInterpreter from nidaqmx._lib import lib_importer, ctypes_byte_str, c_bool32, wrapped_ndpointer from nidaqmx.error_codes import DAQmxErrors, DAQmxWarnings from nidaqmx.errors import DaqError, DaqReadError, DaqWarning, DaqWriteError +from nidaqmx._lib_time import AbsoluteTime _logger = logging.getLogger(__name__) diff --git a/src/codegen/utilities/function_helpers.py b/src/codegen/utilities/function_helpers.py index d39669554..8a428085a 100644 --- a/src/codegen/utilities/function_helpers.py +++ b/src/codegen/utilities/function_helpers.py @@ -201,11 +201,17 @@ def to_param_argtype(parameter): # argtype to convert from unicode to bytes. if parameter.ctypes_data_type == "ctypes.c_char_p": return "ctypes_byte_str" + elif parameter.python_data_type == "datetime": + return "_lib_time.AbsoluteTime" + elif parameter.python_data_type == "timestampEvent": + return "ctypes.c_int32" else: return parameter.ctypes_data_type or parameter.python_data_type else: if parameter.ctypes_data_type == "ctypes.c_char_p": return parameter.ctypes_data_type + elif parameter.python_data_type == "datetime": + return "ctypes.POINTER(_lib_time.AbsoluteTime)" else: return f"ctypes.POINTER({parameter.ctypes_data_type})" diff --git a/src/codegen/utilities/interpreter_helpers.py b/src/codegen/utilities/interpreter_helpers.py index 42902d50a..d4a0ee5a1 100644 --- a/src/codegen/utilities/interpreter_helpers.py +++ b/src/codegen/utilities/interpreter_helpers.py @@ -73,7 +73,6 @@ "SetTimingAttributeExTimestamp", "SetTimingAttributeTimestamp", "SetTrigAttributeTimestamp", - "WaitForValidTimestamp", # Deprecated, not working "GetAnalogPowerUpStates", ] @@ -179,6 +178,8 @@ def generate_interpreter_function_call_args(function_metadata): and function_metadata.attribute_function_type == AttributeFunctionType.SET ): function_call_args.append(type_cast_attribute_set_function_parameter(param)) + elif param.type == "CVIAbsoluteTime": + function_call_args.append(f"AbsoluteTime.from_datetime({param.parameter_name})") else: function_call_args.append(param.parameter_name) @@ -257,6 +258,8 @@ def get_instantiation_lines_for_output(func): instantiation_lines.append( f"{param.parameter_name} = numpy.zeros(size, dtype={param.ctypes_data_type})" ) + elif param.type == "CVIAbsoluteTime": + instantiation_lines.append(f"{param.parameter_name} = _lib_time.AbsoluteTime()") else: instantiation_lines.append(f"{param.parameter_name} = {param.ctypes_data_type}()") for param in get_interpreter_in_out_params(func): @@ -354,6 +357,8 @@ def get_grpc_interpreter_call_params(func, params): has_read_array_parameter = True elif param.is_grpc_enum or (param.is_enum and not param.is_list): grpc_params.append(f"{name}_raw={param.parameter_name}") + elif param.type == "CVIAbsoluteTime": + grpc_params.append(f"{name}=convert_time_to_timestamp({param.parameter_name})") else: if is_write_bytes_param(param): grpc_params.append(f"{name}={param.parameter_name}.tobytes()")