Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CfgTimeStartTrig to daqmx-python #475

Merged
merged 6 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 7 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,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(
Expand Down
15 changes: 15 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 as LibTimestamp


_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -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,
DeborahOoi96 marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
14 changes: 14 additions & 0 deletions generated/nidaqmx/_task_modules/triggering/start_trigger.py
DeborahOoi96 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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
DeborahOoi96 marked this conversation as resolved.
Show resolved Hide resolved

Args:
when (nidaqmx.constants.DateTime): Specifies when to
DeborahOoi96 marked this conversation as resolved.
Show resolved Hide resolved
DeborahOoi96 marked this conversation as resolved.
Show resolved Hide resolved
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
7 changes: 6 additions & 1 deletion 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 Down Expand Up @@ -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 as LibTimestamp
DeborahOoi96 marked this conversation as resolved.
Show resolved Hide resolved


_logger = logging.getLogger(__name__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
_validate_array_dtype(${parameter_name}, ${parameter_dtype})
%endfor
%endif
%for param in params:
DeborahOoi96 marked this conversation as resolved.
Show resolved Hide resolved
%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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
DeborahOoi96 marked this conversation as resolved.
Show resolved Hide resolved
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)})
Expand Down
2 changes: 0 additions & 2 deletions src/codegen/utilities/interpreter_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@
"SetRealTimeAttributeInt32",
"SetRealTimeAttributeUInt32",
"WaitForNextSampleClock",
# Time triggers
"CfgTimeStartTrig",
"GetArmStartTrigTimestampVal",
"GetArmStartTrigTrigWhen",
"GetFirstSampClkWhen",
DeborahOoi96 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down