Skip to content

Commit

Permalink
Add CfgTimeStartTrig to daqmx-python (#475)
Browse files Browse the repository at this point in the history
* Add CfgTimeStartTrig to daqmx-python

* Address comments

* Address comments 2

* Fix lint error

* Address comments

* Add datetime import line
  • Loading branch information
DeborahOoi96 authored Jan 30, 2024
1 parent c5fddf5 commit 5e77102
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 5 deletions.
4 changes: 4 additions & 0 deletions generated/nidaqmx/_base_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 8 additions & 0 deletions generated/nidaqmx/_grpc_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -378,6 +379,13 @@ 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):
response = self._invoke(
self._client.CfgTimeStartTrig,
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):
response = self._invoke(
Expand Down
14 changes: 14 additions & 0 deletions generated/nidaqmx/_library_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -390,6 +391,19 @@ 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
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
lib_importer.task_handle, _lib_time.AbsoluteTime,
ctypes.c_int]

error_code = cfunc(
task, AbsoluteTime.from_datetime(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
Expand Down
14 changes: 14 additions & 0 deletions generated/nidaqmx/_task_modules/triggering/start_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from nidaqmx.constants import (
Coupling, DigitalPatternCondition, DigitalWidthUnits, Edge, Slope,
Timescale, TriggerType, WindowTriggerCondition1)
from datetime import datetime


class StartTrigger:
Expand Down Expand Up @@ -1037,6 +1038,19 @@ 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 (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
Expand Down
11 changes: 8 additions & 3 deletions src/codegen/metadata/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -1429,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'
},
{
Expand All @@ -1447,7 +1452,7 @@
'type': 'int32'
}
],
'python_codegen_method': 'no',
'python_class_name': 'StartTrigger',
'python_description': 'New Start Trigger',
'returns': 'int32'
},
Expand Down
1 change: 1 addition & 0 deletions src/codegen/templates/_grpc_interpreter.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
1 change: 1 addition & 0 deletions src/codegen/templates/_library_interpreter.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
self.check_for_error(error_code)
%else:
self.check_for_error(error_code, ${samps_per_chan_param}.value)
%endif
%endif
2 changes: 2 additions & 0 deletions src/codegen/utilities/function_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "_lib_time.AbsoluteTime"
elif parameter.direction == "in":
# If is string input parameter, use separate custom
# argtype to convert from unicode to bytes.
Expand Down
5 changes: 4 additions & 1 deletion src/codegen/utilities/interpreter_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"SetRealTimeAttributeUInt32",
"WaitForNextSampleClock",
# Time triggers
"CfgTimeStartTrig",
"GetArmStartTrigTimestampVal",
"GetArmStartTrigTrigWhen",
"GetFirstSampClkWhen",
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -354,6 +355,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()")
Expand Down

0 comments on commit 5e77102

Please sign in to comment.