From 2bf5a6a4353a5b5840a6d700e672db7b0e392d15 Mon Sep 17 00:00:00 2001 From: DeborahOoi96 Date: Wed, 24 Jan 2024 15:32:54 +0800 Subject: [PATCH 1/6] Add CfgTimeStartTrig to daqmx-python --- generated/nidaqmx/_base_interpreter.py | 4 ++++ generated/nidaqmx/_grpc_interpreter.py | 7 +++++++ generated/nidaqmx/_library_interpreter.py | 15 +++++++++++++++ .../_task_modules/triggering/start_trigger.py | 14 ++++++++++++++ src/codegen/metadata/functions.py | 7 ++++++- src/codegen/templates/_grpc_interpreter.py.mako | 1 + .../templates/_library_interpreter.py.mako | 1 + .../default_grpc_function_call.py.mako | 5 +++++ .../default_c_function_call.py.mako | 13 ++++++++++++- src/codegen/utilities/interpreter_helpers.py | 2 -- 10 files changed, 65 insertions(+), 4 deletions(-) diff --git a/generated/nidaqmx/_base_interpreter.py b/generated/nidaqmx/_base_interpreter.py index 3cd86894..04858e17 100644 --- a/generated/nidaqmx/_base_interpreter.py +++ b/generated/nidaqmx/_base_interpreter.py @@ -147,6 +147,10 @@ def cfg_samp_clk_timing( samps_per_chan): raise NotImplementedError + @abc.abstractmethod + def cfg_time_start_trig(self, task, when, timescale): + raise NotImplementedError + @abc.abstractmethod def cfg_watchdog_ao_expir_states( self, task, channel_names, expir_state_array, output_type_array): diff --git a/generated/nidaqmx/_grpc_interpreter.py b/generated/nidaqmx/_grpc_interpreter.py index 1ef808a8..522ff13d 100644 --- a/generated/nidaqmx/_grpc_interpreter.py +++ b/generated/nidaqmx/_grpc_interpreter.py @@ -17,6 +17,7 @@ from nidaqmx._stubs import nidaqmx_pb2_grpc as nidaqmx_grpc from nidaqmx._stubs import session_pb2 as session_grpc_types from nidaqmx.error_codes import DAQmxErrors +from nidaqmx._grpc_time import convert_time_to_timestamp _logger = logging.getLogger(__name__) @@ -378,6 +379,12 @@ def cfg_samp_clk_timing( active_edge_raw=active_edge, sample_mode_raw=sample_mode, samps_per_chan=samps_per_chan)) + def cfg_time_start_trig(self, task, when, timescale): + when = convert_time_to_timestamp(when) + response = self._invoke( + self._client.CfgTimeStartTrig, + grpc_types.CfgTimeStartTrigRequest(task=task, when=when, timescale_raw=timescale)) + def cfg_watchdog_ao_expir_states( self, task, channel_names, expir_state_array, output_type_array): response = self._invoke( diff --git a/generated/nidaqmx/_library_interpreter.py b/generated/nidaqmx/_library_interpreter.py index aa4cc075..534575d4 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 as LibTimestamp _logger = logging.getLogger(__name__) @@ -390,6 +391,20 @@ def cfg_samp_clk_timing( task, source, rate, active_edge, sample_mode, samps_per_chan) self.check_for_error(error_code) + def cfg_time_start_trig(self, task, when, timescale): + cfunc = lib_importer.windll.DAQmxCfgTimeStartTrig + when = LibTimestamp.from_datetime(when) + if cfunc.argtypes is None: + with cfunc.arglock: + if cfunc.argtypes is None: + cfunc.argtypes = [ + lib_importer.task_handle, ctypes.CVIAbsoluteTime, + ctypes.c_int] + + error_code = cfunc( + task, when, timescale) + self.check_for_error(error_code) + def cfg_watchdog_ao_expir_states( self, task, channel_names, expir_state_array, output_type_array): cfunc = lib_importer.windll.DAQmxCfgWatchdogAOExpirStates diff --git a/generated/nidaqmx/_task_modules/triggering/start_trigger.py b/generated/nidaqmx/_task_modules/triggering/start_trigger.py index e6ad6485..054a6ceb 100644 --- a/generated/nidaqmx/_task_modules/triggering/start_trigger.py +++ b/generated/nidaqmx/_task_modules/triggering/start_trigger.py @@ -1037,6 +1037,20 @@ def cfg_dig_pattern_start_trig( self._interpreter.cfg_dig_pattern_start_trig( self._handle, trigger_source, trigger_pattern, trigger_when.value) + def cfg_time_start_trig(self, when, timescale=Timescale.USE_HOST): + """ + New Start Trigger + + Args: + when (nidaqmx.constants.DateTime): Specifies when to + trigger. + timescale (Optional[nidaqmx.constants.Timescale]): Specifies + the start trigger timestamp time scale. + """ + + self._interpreter.cfg_time_start_trig( + self._handle, when, timescale.value) + def disable_start_trig(self): """ Configures the task to start acquiring or generating samples diff --git a/src/codegen/metadata/functions.py b/src/codegen/metadata/functions.py index 6b4e4713..ac1d2598 100644 --- a/src/codegen/metadata/functions.py +++ b/src/codegen/metadata/functions.py @@ -1413,6 +1413,11 @@ }, 'CfgTimeStartTrig': { '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', @@ -1447,7 +1452,7 @@ 'type': 'int32' } ], - 'python_codegen_method': 'no', + 'python_class_name': 'StartTrigger', 'python_description': 'New Start Trigger', 'returns': 'int32' }, diff --git a/src/codegen/templates/_grpc_interpreter.py.mako b/src/codegen/templates/_grpc_interpreter.py.mako index fc940b04..ac0be5ed 100644 --- a/src/codegen/templates/_grpc_interpreter.py.mako +++ b/src/codegen/templates/_grpc_interpreter.py.mako @@ -33,6 +33,7 @@ from nidaqmx._stubs import nidaqmx_pb2 as grpc_types from nidaqmx._stubs import nidaqmx_pb2_grpc as nidaqmx_grpc from nidaqmx._stubs import session_pb2 as session_grpc_types from nidaqmx.error_codes import DAQmxErrors +from nidaqmx._grpc_time import convert_time_to_timestamp _logger = logging.getLogger(__name__) diff --git a/src/codegen/templates/_library_interpreter.py.mako b/src/codegen/templates/_library_interpreter.py.mako index d0ba335f..e2ad6b83 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 as LibTimestamp _logger = logging.getLogger(__name__) diff --git a/src/codegen/templates/grpc_interpreter/default_grpc_function_call.py.mako b/src/codegen/templates/grpc_interpreter/default_grpc_function_call.py.mako index 4dada789..126c281c 100644 --- a/src/codegen/templates/grpc_interpreter/default_grpc_function_call.py.mako +++ b/src/codegen/templates/grpc_interpreter/default_grpc_function_call.py.mako @@ -41,6 +41,11 @@ _validate_array_dtype(${parameter_name}, ${parameter_dtype}) %endfor %endif +%for param in params: + %if "CVIAbsoluteTime" == param._type: + ${param._parameters_name} = convert_time_to_timestamp(${param._parameters_name}) + %endif +%endfor response = self._invoke( self._client.${snake_to_pascal(function.function_name)}, %if (len(function.function_name) + len(grpc_interpreter_params)) > 68: diff --git a/src/codegen/templates/library_interpreter/default_c_function_call.py.mako b/src/codegen/templates/library_interpreter/default_c_function_call.py.mako index 5e05525e..1df6ee15 100644 --- a/src/codegen/templates/library_interpreter/default_c_function_call.py.mako +++ b/src/codegen/templates/library_interpreter/default_c_function_call.py.mako @@ -14,11 +14,22 @@ samps_per_chan_param = get_samps_per_chan_read_or_write_param(function.base_parameters) %>\ cfunc = lib_importer.${'windll' if function.calling_convention == 'StdCall' else 'cdll'}.DAQmx${function.c_function_name} +<% + argtypes = get_argument_types(function) +%>\ +%if 'DateTime' in argtypes: + <% + index = argtypes.index('DateTime') + name = function_call_args[index] + argtypes[index] = 'ctypes.CVIAbsoluteTime' + %>\ + ${name} = LibTimestamp.from_datetime(${name}) +%endif if cfunc.argtypes is None: with cfunc.arglock: if cfunc.argtypes is None: cfunc.argtypes = [ - ${', '.join(get_argument_types(function)) | wrap(24, 24)}] + ${', '.join(argtypes) | wrap(24, 24)}] error_code = cfunc( ${', '.join(function_call_args) | wrap(12, 12)}) diff --git a/src/codegen/utilities/interpreter_helpers.py b/src/codegen/utilities/interpreter_helpers.py index 42902d50..e5720c2d 100644 --- a/src/codegen/utilities/interpreter_helpers.py +++ b/src/codegen/utilities/interpreter_helpers.py @@ -53,8 +53,6 @@ "SetRealTimeAttributeInt32", "SetRealTimeAttributeUInt32", "WaitForNextSampleClock", - # Time triggers - "CfgTimeStartTrig", "GetArmStartTrigTimestampVal", "GetArmStartTrigTrigWhen", "GetFirstSampClkWhen", From de4de872cbc5beb2ed12a3791b81bf694e36d0f4 Mon Sep 17 00:00:00 2001 From: DeborahOoi96 Date: Fri, 26 Jan 2024 18:56:02 +0800 Subject: [PATCH 2/6] Address comments --- generated/nidaqmx/_grpc_interpreter.py | 5 +++-- generated/nidaqmx/_library_interpreter.py | 4 ++-- src/codegen/templates/_library_interpreter.py.mako | 2 +- .../default_grpc_function_call.py.mako | 5 ----- .../default_c_function_call.py.mako | 11 +++-------- .../double_c_function_call.py.mako | 2 +- .../library_interpreter/event_function_call.py.mako | 2 +- src/codegen/utilities/function_helpers.py | 2 ++ src/codegen/utilities/interpreter_helpers.py | 9 ++++++++- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/generated/nidaqmx/_grpc_interpreter.py b/generated/nidaqmx/_grpc_interpreter.py index 522ff13d..75ef29fe 100644 --- a/generated/nidaqmx/_grpc_interpreter.py +++ b/generated/nidaqmx/_grpc_interpreter.py @@ -380,10 +380,11 @@ def cfg_samp_clk_timing( samps_per_chan=samps_per_chan)) def cfg_time_start_trig(self, task, when, timescale): - when = convert_time_to_timestamp(when) response = self._invoke( self._client.CfgTimeStartTrig, - grpc_types.CfgTimeStartTrigRequest(task=task, when=when, timescale_raw=timescale)) + grpc_types.CfgTimeStartTrigRequest( + task=task, when=convert_time_to_timestamp(when), + timescale_raw=timescale)) def cfg_watchdog_ao_expir_states( self, task, channel_names, expir_state_array, output_type_array): diff --git a/generated/nidaqmx/_library_interpreter.py b/generated/nidaqmx/_library_interpreter.py index 534575d4..c47b93d0 100644 --- a/generated/nidaqmx/_library_interpreter.py +++ b/generated/nidaqmx/_library_interpreter.py @@ -12,7 +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 as LibTimestamp +from nidaqmx._lib_time import AbsoluteTime _logger = logging.getLogger(__name__) @@ -393,7 +393,7 @@ def cfg_samp_clk_timing( def cfg_time_start_trig(self, task, when, timescale): cfunc = lib_importer.windll.DAQmxCfgTimeStartTrig - when = LibTimestamp.from_datetime(when) + when = AbsoluteTime.from_datetime(when) if cfunc.argtypes is None: with cfunc.arglock: if cfunc.argtypes is None: diff --git a/src/codegen/templates/_library_interpreter.py.mako b/src/codegen/templates/_library_interpreter.py.mako index e2ad6b83..f5346554 100644 --- a/src/codegen/templates/_library_interpreter.py.mako +++ b/src/codegen/templates/_library_interpreter.py.mako @@ -28,7 +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 as LibTimestamp +from nidaqmx._lib_time import AbsoluteTime _logger = logging.getLogger(__name__) diff --git a/src/codegen/templates/grpc_interpreter/default_grpc_function_call.py.mako b/src/codegen/templates/grpc_interpreter/default_grpc_function_call.py.mako index 126c281c..4dada789 100644 --- a/src/codegen/templates/grpc_interpreter/default_grpc_function_call.py.mako +++ b/src/codegen/templates/grpc_interpreter/default_grpc_function_call.py.mako @@ -41,11 +41,6 @@ _validate_array_dtype(${parameter_name}, ${parameter_dtype}) %endfor %endif -%for param in params: - %if "CVIAbsoluteTime" == param._type: - ${param._parameters_name} = convert_time_to_timestamp(${param._parameters_name}) - %endif -%endfor response = self._invoke( self._client.${snake_to_pascal(function.function_name)}, %if (len(function.function_name) + len(grpc_interpreter_params)) > 68: diff --git a/src/codegen/templates/library_interpreter/default_c_function_call.py.mako b/src/codegen/templates/library_interpreter/default_c_function_call.py.mako index 1df6ee15..0a412aa7 100644 --- a/src/codegen/templates/library_interpreter/default_c_function_call.py.mako +++ b/src/codegen/templates/library_interpreter/default_c_function_call.py.mako @@ -7,7 +7,7 @@ ) from codegen.utilities.text_wrappers import wrap, docstring_wrap - function_call_args = generate_interpreter_function_call_args(function) + function_call_args, dateTime_args = generate_interpreter_function_call_args(function) # samps_per_chan_param includes the keyword argument (samps_per_chan_read= # or samps_per_chan_written=) @@ -17,13 +17,8 @@ <% argtypes = get_argument_types(function) %>\ -%if 'DateTime' in argtypes: - <% - index = argtypes.index('DateTime') - name = function_call_args[index] - argtypes[index] = 'ctypes.CVIAbsoluteTime' - %>\ - ${name} = LibTimestamp.from_datetime(${name}) +%if dateTime_args: + ${'\n\t\t'.join(dateTime_args)} %endif if cfunc.argtypes is None: with cfunc.arglock: diff --git a/src/codegen/templates/library_interpreter/double_c_function_call.py.mako b/src/codegen/templates/library_interpreter/double_c_function_call.py.mako index 7ddec356..ffc7e544 100644 --- a/src/codegen/templates/library_interpreter/double_c_function_call.py.mako +++ b/src/codegen/templates/library_interpreter/double_c_function_call.py.mako @@ -9,7 +9,7 @@ from codegen.utilities.function_helpers import instantiate_explicit_output_param from codegen.utilities.text_wrappers import wrap, docstring_wrap - function_call_args = generate_interpreter_function_call_args(function) + function_call_args, dateTime_args = generate_interpreter_function_call_args(function) explicit_output_param = get_output_param_with_ivi_dance_mechanism(function) %>\ cfunc = lib_importer.${'windll' if function.calling_convention == 'StdCall' else 'cdll'}.DAQmx${function.c_function_name} diff --git a/src/codegen/templates/library_interpreter/event_function_call.py.mako b/src/codegen/templates/library_interpreter/event_function_call.py.mako index c414ee7c..c02e0fec 100644 --- a/src/codegen/templates/library_interpreter/event_function_call.py.mako +++ b/src/codegen/templates/library_interpreter/event_function_call.py.mako @@ -19,7 +19,7 @@ callback_func_param = get_callback_func_param(function) callback_param_types = get_callback_param_data_types(function) event_name = get_event_name(function) - function_call_args = generate_interpreter_function_call_args(function) + function_call_args, dateTime_args = generate_interpreter_function_call_args(function) %>\ ${callback_func_param.type} = ctypes.CFUNCTYPE( ${', '.join(callback_param_types) | wrap(12)}) diff --git a/src/codegen/utilities/function_helpers.py b/src/codegen/utilities/function_helpers.py index d3966955..7d6ba315 100644 --- a/src/codegen/utilities/function_helpers.py +++ b/src/codegen/utilities/function_helpers.py @@ -196,6 +196,8 @@ def to_param_argtype(parameter): else: if parameter.ctypes_data_type == "ctypes.TaskHandle": return "lib_importer.task_handle" + elif parameter.python_data_type == "DateTime": + return "ctypes.CVIAbsoluteTime" elif parameter.direction == "in": # If is string input parameter, use separate custom # argtype to convert from unicode to bytes. diff --git a/src/codegen/utilities/interpreter_helpers.py b/src/codegen/utilities/interpreter_helpers.py index e5720c2d..fca6be8b 100644 --- a/src/codegen/utilities/interpreter_helpers.py +++ b/src/codegen/utilities/interpreter_helpers.py @@ -53,6 +53,7 @@ "SetRealTimeAttributeInt32", "SetRealTimeAttributeUInt32", "WaitForNextSampleClock", + # Time triggers "GetArmStartTrigTimestampVal", "GetArmStartTrigTrigWhen", "GetFirstSampClkWhen", @@ -133,6 +134,7 @@ def get_interpreter_functions(metadata): def generate_interpreter_function_call_args(function_metadata): """Gets function call arguments.""" function_call_args = [] + dateTime_args = [] size_values = {} interpreter_parameters = get_interpreter_parameters(function_metadata) for param in interpreter_parameters: @@ -156,6 +158,9 @@ def generate_interpreter_function_call_args(function_metadata): function_call_args.append("None") elif is_event_function(function_metadata) and param.parameter_name == "callback_function": function_call_args.append("callback_method_ptr") + elif param.type == "CVIAbsoluteTime": + dateTime_args.append(f"{param.parameter_name} = AbsoluteTime.from_datetime({param.parameter_name})") + function_call_args.append(param.parameter_name) elif param.direction == "out" or ( param.is_pointer and param.parameter_name != "callback_data" ): @@ -180,7 +185,7 @@ def generate_interpreter_function_call_args(function_metadata): else: function_call_args.append(param.parameter_name) - return function_call_args + return function_call_args, dateTime_args def get_argument_types(functions_metadata): @@ -352,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()") From 4b6829ade0f89171c39ddd91873d21379276cbff Mon Sep 17 00:00:00 2001 From: DeborahOoi96 Date: Fri, 26 Jan 2024 19:00:00 +0800 Subject: [PATCH 3/6] Address comments 2 --- generated/nidaqmx/_library_interpreter.py | 2 +- src/codegen/utilities/function_helpers.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/generated/nidaqmx/_library_interpreter.py b/generated/nidaqmx/_library_interpreter.py index c47b93d0..cd4bb7f3 100644 --- a/generated/nidaqmx/_library_interpreter.py +++ b/generated/nidaqmx/_library_interpreter.py @@ -398,7 +398,7 @@ def cfg_time_start_trig(self, task, when, timescale): with cfunc.arglock: if cfunc.argtypes is None: cfunc.argtypes = [ - lib_importer.task_handle, ctypes.CVIAbsoluteTime, + lib_importer.task_handle, _lib_time.AbsoluteTime, ctypes.c_int] error_code = cfunc( diff --git a/src/codegen/utilities/function_helpers.py b/src/codegen/utilities/function_helpers.py index 7d6ba315..84b04346 100644 --- a/src/codegen/utilities/function_helpers.py +++ b/src/codegen/utilities/function_helpers.py @@ -197,7 +197,7 @@ def to_param_argtype(parameter): if parameter.ctypes_data_type == "ctypes.TaskHandle": return "lib_importer.task_handle" elif parameter.python_data_type == "DateTime": - return "ctypes.CVIAbsoluteTime" + return "_lib_time.AbsoluteTime" elif parameter.direction == "in": # If is string input parameter, use separate custom # argtype to convert from unicode to bytes. From d29aa15fd06f3472d4112c9f0f5c763ff5e96a0f Mon Sep 17 00:00:00 2001 From: DeborahOoi96 Date: Fri, 26 Jan 2024 19:02:09 +0800 Subject: [PATCH 4/6] Fix lint error --- src/codegen/utilities/interpreter_helpers.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/codegen/utilities/interpreter_helpers.py b/src/codegen/utilities/interpreter_helpers.py index fca6be8b..31cc276b 100644 --- a/src/codegen/utilities/interpreter_helpers.py +++ b/src/codegen/utilities/interpreter_helpers.py @@ -159,7 +159,9 @@ def generate_interpreter_function_call_args(function_metadata): elif is_event_function(function_metadata) and param.parameter_name == "callback_function": function_call_args.append("callback_method_ptr") elif param.type == "CVIAbsoluteTime": - dateTime_args.append(f"{param.parameter_name} = AbsoluteTime.from_datetime({param.parameter_name})") + dateTime_args.append( + f"{param.parameter_name} = AbsoluteTime.from_datetime({param.parameter_name})" + ) function_call_args.append(param.parameter_name) elif param.direction == "out" or ( param.is_pointer and param.parameter_name != "callback_data" From ef00fbb0f9ce6780f5d5fdf7c623b9a6bae44e40 Mon Sep 17 00:00:00 2001 From: DeborahOoi96 Date: Sun, 28 Jan 2024 22:46:18 +0800 Subject: [PATCH 5/6] Address comments --- generated/nidaqmx/_library_interpreter.py | 3 +-- .../_task_modules/triggering/start_trigger.py | 3 +-- src/codegen/metadata/functions.py | 4 ++-- .../default_c_function_call.py.mako | 12 +++--------- .../double_c_function_call.py.mako | 2 +- .../library_interpreter/event_function_call.py.mako | 2 +- src/codegen/utilities/function_helpers.py | 2 +- src/codegen/utilities/interpreter_helpers.py | 10 +++------- 8 files changed, 13 insertions(+), 25 deletions(-) diff --git a/generated/nidaqmx/_library_interpreter.py b/generated/nidaqmx/_library_interpreter.py index cd4bb7f3..80b99fd6 100644 --- a/generated/nidaqmx/_library_interpreter.py +++ b/generated/nidaqmx/_library_interpreter.py @@ -393,7 +393,6 @@ def cfg_samp_clk_timing( def cfg_time_start_trig(self, task, when, timescale): cfunc = lib_importer.windll.DAQmxCfgTimeStartTrig - when = AbsoluteTime.from_datetime(when) if cfunc.argtypes is None: with cfunc.arglock: if cfunc.argtypes is None: @@ -402,7 +401,7 @@ def cfg_time_start_trig(self, task, when, timescale): ctypes.c_int] error_code = cfunc( - task, when, timescale) + task, AbsoluteTime.from_datetime(when), timescale) self.check_for_error(error_code) def cfg_watchdog_ao_expir_states( diff --git a/generated/nidaqmx/_task_modules/triggering/start_trigger.py b/generated/nidaqmx/_task_modules/triggering/start_trigger.py index 054a6ceb..c5d96acf 100644 --- a/generated/nidaqmx/_task_modules/triggering/start_trigger.py +++ b/generated/nidaqmx/_task_modules/triggering/start_trigger.py @@ -1042,8 +1042,7 @@ def cfg_time_start_trig(self, when, timescale=Timescale.USE_HOST): New Start Trigger Args: - when (nidaqmx.constants.DateTime): Specifies when to - trigger. + when (datetime): Specifies when to trigger. timescale (Optional[nidaqmx.constants.Timescale]): Specifies the start trigger timestamp time scale. """ diff --git a/src/codegen/metadata/functions.py b/src/codegen/metadata/functions.py index ac1d2598..80f5d13a 100644 --- a/src/codegen/metadata/functions.py +++ b/src/codegen/metadata/functions.py @@ -1434,9 +1434,9 @@ 'direction': 'in', 'is_optional_in_python': False, 'name': 'when', - 'python_data_type': 'DateTime', + 'python_data_type': 'datetime', 'python_description': 'Specifies when to trigger.', - 'python_type_annotation': 'nidaqmx.constants.DateTime', + 'python_type_annotation': 'datetime', 'type': 'CVIAbsoluteTime' }, { diff --git a/src/codegen/templates/library_interpreter/default_c_function_call.py.mako b/src/codegen/templates/library_interpreter/default_c_function_call.py.mako index 0a412aa7..d16c6be0 100644 --- a/src/codegen/templates/library_interpreter/default_c_function_call.py.mako +++ b/src/codegen/templates/library_interpreter/default_c_function_call.py.mako @@ -7,24 +7,18 @@ ) from codegen.utilities.text_wrappers import wrap, docstring_wrap - function_call_args, dateTime_args = generate_interpreter_function_call_args(function) + function_call_args = generate_interpreter_function_call_args(function) # samps_per_chan_param includes the keyword argument (samps_per_chan_read= # or samps_per_chan_written=) samps_per_chan_param = get_samps_per_chan_read_or_write_param(function.base_parameters) %>\ cfunc = lib_importer.${'windll' if function.calling_convention == 'StdCall' else 'cdll'}.DAQmx${function.c_function_name} -<% - argtypes = get_argument_types(function) -%>\ -%if dateTime_args: - ${'\n\t\t'.join(dateTime_args)} -%endif if cfunc.argtypes is None: with cfunc.arglock: if cfunc.argtypes is None: cfunc.argtypes = [ - ${', '.join(argtypes) | wrap(24, 24)}] + ${', '.join(get_argument_types(function)) | wrap(24, 24)}] error_code = cfunc( ${', '.join(function_call_args) | wrap(12, 12)}) @@ -32,4 +26,4 @@ self.check_for_error(error_code) %else: self.check_for_error(error_code, ${samps_per_chan_param}.value) -%endif +%endif \ No newline at end of file diff --git a/src/codegen/templates/library_interpreter/double_c_function_call.py.mako b/src/codegen/templates/library_interpreter/double_c_function_call.py.mako index ffc7e544..7ddec356 100644 --- a/src/codegen/templates/library_interpreter/double_c_function_call.py.mako +++ b/src/codegen/templates/library_interpreter/double_c_function_call.py.mako @@ -9,7 +9,7 @@ from codegen.utilities.function_helpers import instantiate_explicit_output_param from codegen.utilities.text_wrappers import wrap, docstring_wrap - function_call_args, dateTime_args = generate_interpreter_function_call_args(function) + function_call_args = generate_interpreter_function_call_args(function) explicit_output_param = get_output_param_with_ivi_dance_mechanism(function) %>\ cfunc = lib_importer.${'windll' if function.calling_convention == 'StdCall' else 'cdll'}.DAQmx${function.c_function_name} diff --git a/src/codegen/templates/library_interpreter/event_function_call.py.mako b/src/codegen/templates/library_interpreter/event_function_call.py.mako index c02e0fec..c414ee7c 100644 --- a/src/codegen/templates/library_interpreter/event_function_call.py.mako +++ b/src/codegen/templates/library_interpreter/event_function_call.py.mako @@ -19,7 +19,7 @@ callback_func_param = get_callback_func_param(function) callback_param_types = get_callback_param_data_types(function) event_name = get_event_name(function) - function_call_args, dateTime_args = generate_interpreter_function_call_args(function) + function_call_args = generate_interpreter_function_call_args(function) %>\ ${callback_func_param.type} = ctypes.CFUNCTYPE( ${', '.join(callback_param_types) | wrap(12)}) diff --git a/src/codegen/utilities/function_helpers.py b/src/codegen/utilities/function_helpers.py index 84b04346..30dbc00c 100644 --- a/src/codegen/utilities/function_helpers.py +++ b/src/codegen/utilities/function_helpers.py @@ -196,7 +196,7 @@ def to_param_argtype(parameter): else: if parameter.ctypes_data_type == "ctypes.TaskHandle": return "lib_importer.task_handle" - elif parameter.python_data_type == "DateTime": + elif parameter.python_data_type == "datetime": return "_lib_time.AbsoluteTime" elif parameter.direction == "in": # If is string input parameter, use separate custom diff --git a/src/codegen/utilities/interpreter_helpers.py b/src/codegen/utilities/interpreter_helpers.py index 31cc276b..83b04aff 100644 --- a/src/codegen/utilities/interpreter_helpers.py +++ b/src/codegen/utilities/interpreter_helpers.py @@ -134,7 +134,6 @@ def get_interpreter_functions(metadata): def generate_interpreter_function_call_args(function_metadata): """Gets function call arguments.""" function_call_args = [] - dateTime_args = [] size_values = {} interpreter_parameters = get_interpreter_parameters(function_metadata) for param in interpreter_parameters: @@ -158,11 +157,6 @@ def generate_interpreter_function_call_args(function_metadata): function_call_args.append("None") elif is_event_function(function_metadata) and param.parameter_name == "callback_function": function_call_args.append("callback_method_ptr") - elif param.type == "CVIAbsoluteTime": - dateTime_args.append( - f"{param.parameter_name} = AbsoluteTime.from_datetime({param.parameter_name})" - ) - function_call_args.append(param.parameter_name) elif param.direction == "out" or ( param.is_pointer and param.parameter_name != "callback_data" ): @@ -184,10 +178,12 @@ 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) - return function_call_args, dateTime_args + return function_call_args def get_argument_types(functions_metadata): From d030b1d66d943b872f484984a4a2dbe227a00ef7 Mon Sep 17 00:00:00 2001 From: DeborahOoi96 Date: Tue, 30 Jan 2024 14:45:51 +0800 Subject: [PATCH 6/6] Add datetime import line --- generated/nidaqmx/_task_modules/triggering/start_trigger.py | 1 + .../templates/_task_modules/triggering/start_trigger.py.mako | 1 + 2 files changed, 2 insertions(+) diff --git a/generated/nidaqmx/_task_modules/triggering/start_trigger.py b/generated/nidaqmx/_task_modules/triggering/start_trigger.py index c5d96acf..2af953e5 100644 --- a/generated/nidaqmx/_task_modules/triggering/start_trigger.py +++ b/generated/nidaqmx/_task_modules/triggering/start_trigger.py @@ -6,6 +6,7 @@ from nidaqmx.constants import ( Coupling, DigitalPatternCondition, DigitalWidthUnits, Edge, Slope, Timescale, TriggerType, WindowTriggerCondition1) +from datetime import datetime class StartTrigger: diff --git a/src/codegen/templates/_task_modules/triggering/start_trigger.py.mako b/src/codegen/templates/_task_modules/triggering/start_trigger.py.mako index 3288f13e..d073c45e 100644 --- a/src/codegen/templates/_task_modules/triggering/start_trigger.py.mako +++ b/src/codegen/templates/_task_modules/triggering/start_trigger.py.mako @@ -18,6 +18,7 @@ from nidaqmx.system.physical_channel import _PhysicalChannelAlternateConstructor from nidaqmx.constants import ( ${', '.join([c for c in enums_used]) | wrap(4, 4)}) %endif +from datetime import datetime class StartTrigger: