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 4 commits
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
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
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


_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 = AbsoluteTime.from_datetime(when)
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, 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


_logger = logging.getLogger(__name__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@
)
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)
DeborahOoi96 marked this conversation as resolved.
Show resolved Hide resolved

# 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)}
DeborahOoi96 marked this conversation as resolved.
Show resolved Hide resolved
%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)})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)})
Expand Down
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
11 changes: 9 additions & 2 deletions 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",
DeborahOoi96 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -135,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:
Expand All @@ -158,6 +158,11 @@ 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":
DeborahOoi96 marked this conversation as resolved.
Show resolved Hide resolved
dateTime_args.append(
f"{param.parameter_name} = AbsoluteTime.from_datetime({param.parameter_name})"
)
function_call_args.append(param.parameter_name)
DeborahOoi96 marked this conversation as resolved.
Show resolved Hide resolved
elif param.direction == "out" or (
param.is_pointer and param.parameter_name != "callback_data"
):
Expand All @@ -182,7 +187,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
DeborahOoi96 marked this conversation as resolved.
Show resolved Hide resolved


def get_argument_types(functions_metadata):
Expand Down Expand Up @@ -354,6 +359,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
Loading