Skip to content

Commit 53c8ef9

Browse files
authored
Add "When" attribute to start_trigger.py (#481)
* Add when attribute to start_trigger.py * Fix libtime issue * Address comments * Try to fix pipeline * Fix python file take 2
1 parent a6b070d commit 53c8ef9

File tree

10 files changed

+110
-22
lines changed

10 files changed

+110
-22
lines changed

generated/nidaqmx/_base_interpreter.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,10 @@ def get_trig_attribute_int32_array(self, task, attribute):
10921092
def get_trig_attribute_string(self, task, attribute):
10931093
raise NotImplementedError
10941094

1095+
@abc.abstractmethod
1096+
def get_trig_attribute_timestamp(self, task, attribute):
1097+
raise NotImplementedError
1098+
10951099
@abc.abstractmethod
10961100
def get_trig_attribute_uint32(self, task, attribute):
10971101
raise NotImplementedError
@@ -1572,6 +1576,10 @@ def set_trig_attribute_int32_array(self, task, attribute, value):
15721576
def set_trig_attribute_string(self, task, attribute, value):
15731577
raise NotImplementedError
15741578

1579+
@abc.abstractmethod
1580+
def set_trig_attribute_timestamp(self, task, attribute, value):
1581+
raise NotImplementedError
1582+
15751583
@abc.abstractmethod
15761584
def set_trig_attribute_uint32(self, task, attribute, value):
15771585
raise NotImplementedError

generated/nidaqmx/_grpc_interpreter.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from nidaqmx._stubs import nidaqmx_pb2_grpc as nidaqmx_grpc
1818
from nidaqmx._stubs import session_pb2 as session_grpc_types
1919
from nidaqmx.error_codes import DAQmxErrors
20-
from nidaqmx._grpc_time import convert_time_to_timestamp
20+
from nidaqmx._grpc_time import convert_time_to_timestamp, convert_timestamp_to_time
2121

2222
_logger = logging.getLogger(__name__)
2323

@@ -2180,6 +2180,12 @@ def get_trig_attribute_string(self, task, attribute):
21802180
grpc_types.GetTrigAttributeStringRequest(task=task, attribute_raw=attribute))
21812181
return response.value
21822182

2183+
def get_trig_attribute_timestamp(self, task, attribute):
2184+
response = self._invoke(
2185+
self._client.GetTrigAttributeTimestamp,
2186+
grpc_types.GetTrigAttributeTimestampRequest(task=task, attribute_raw=attribute))
2187+
return convert_timestamp_to_time(response.value)
2188+
21832189
def get_trig_attribute_uint32(self, task, attribute):
21842190
response = self._invoke(
21852191
self._client.GetTrigAttributeUInt32,
@@ -3126,6 +3132,13 @@ def set_trig_attribute_string(self, task, attribute, value):
31263132
grpc_types.SetTrigAttributeStringRequest(
31273133
task=task, attribute_raw=attribute, value=value))
31283134

3135+
def set_trig_attribute_timestamp(self, task, attribute, value):
3136+
response = self._invoke(
3137+
self._client.SetTrigAttributeTimestamp,
3138+
grpc_types.SetTrigAttributeTimestampRequest(
3139+
task=task, attribute_raw=attribute,
3140+
value=convert_time_to_timestamp(value)))
3141+
31293142
def set_trig_attribute_uint32(self, task, attribute, value):
31303143
response = self._invoke(
31313144
self._client.SetTrigAttributeUInt32,

generated/nidaqmx/_library_interpreter.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,7 @@ def cfg_time_start_trig(self, task, when, timescale):
397397
with cfunc.arglock:
398398
if cfunc.argtypes is None:
399399
cfunc.argtypes = [
400-
lib_importer.task_handle, _lib_time.AbsoluteTime,
401-
ctypes.c_int]
400+
lib_importer.task_handle, AbsoluteTime, ctypes.c_int]
402401

403402
error_code = cfunc(
404403
task, AbsoluteTime.from_datetime(when), timescale)
@@ -3672,6 +3671,21 @@ def get_trig_attribute_string(self, task, attribute):
36723671
self.check_for_error(size_or_code)
36733672
return value.value.decode('ascii')
36743673

3674+
def get_trig_attribute_timestamp(self, task, attribute):
3675+
value = AbsoluteTime()
3676+
3677+
cfunc = lib_importer.cdll.DAQmxGetTrigAttribute
3678+
if cfunc.argtypes is None:
3679+
with cfunc.arglock:
3680+
if cfunc.argtypes is None:
3681+
cfunc.argtypes = [
3682+
lib_importer.task_handle, ctypes.c_int32]
3683+
3684+
error_code = cfunc(
3685+
task, attribute, ctypes.byref(value))
3686+
self.check_for_error(error_code)
3687+
return value
3688+
36753689
def get_trig_attribute_uint32(self, task, attribute):
36763690
value = ctypes.c_uint32()
36773691

@@ -5333,6 +5347,18 @@ def set_trig_attribute_string(self, task, attribute, value):
53335347
task, attribute, value.encode('ascii'))
53345348
self.check_for_error(error_code)
53355349

5350+
def set_trig_attribute_timestamp(self, task, attribute, value):
5351+
cfunc = lib_importer.cdll.DAQmxSetTrigAttribute
5352+
if cfunc.argtypes is None:
5353+
with cfunc.arglock:
5354+
if cfunc.argtypes is None:
5355+
cfunc.argtypes = [
5356+
lib_importer.task_handle, ctypes.c_int32]
5357+
5358+
error_code = cfunc(
5359+
task, attribute, AbsoluteTime.from_datetime(value))
5360+
self.check_for_error(error_code)
5361+
53365362
def set_trig_attribute_uint32(self, task, attribute, value):
53375363
cfunc = lib_importer.cdll.DAQmxSetTrigAttribute
53385364
if cfunc.argtypes is None:

generated/nidaqmx/_task_modules/triggering/arm_start_trigger.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,20 @@ def trig_type(self, val):
231231
def trig_type(self):
232232
self._interpreter.reset_trig_attribute(self._handle, 0x1414)
233233

234+
@property
235+
def trig_when(self):
236+
"""
237+
datetime: Specifies when to trigger the arm start trigger.
238+
"""
239+
240+
val = self._interpreter.get_trig_attribute_timestamp(self._handle, 0x3131)
241+
return val
242+
243+
@trig_when.setter
244+
def trig_when(self, val):
245+
self._interpreter.set_trig_attribute_timestamp(self._handle, 0x3131, val)
246+
247+
@trig_when.deleter
248+
def trig_when(self):
249+
self._interpreter.reset_trig_attribute(self._handle, 0x3131)
250+

generated/nidaqmx/_task_modules/triggering/start_trigger.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,6 +919,23 @@ def trig_type(self, val):
919919
def trig_type(self):
920920
self._interpreter.reset_trig_attribute(self._handle, 0x1393)
921921

922+
@property
923+
def trig_when(self):
924+
"""
925+
datetime: Specifies when to trigger the start trigger.
926+
"""
927+
928+
val = self._interpreter.get_trig_attribute_timestamp(self._handle, 0x304d)
929+
return val
930+
931+
@trig_when.setter
932+
def trig_when(self, val):
933+
self._interpreter.set_trig_attribute_timestamp(self._handle, 0x304d, val)
934+
935+
@trig_when.deleter
936+
def trig_when(self):
937+
self._interpreter.reset_trig_attribute(self._handle, 0x304d)
938+
922939
@property
923940
def trig_win(self):
924941
"""

src/codegen/metadata/attributes.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25834,7 +25834,7 @@
2583425834
'is_python_object': False,
2583525835
'name': 'SYNC_PULSE_TIME_WHEN',
2583625836
'python_class_name': 'Timing',
25837-
'python_data_type': 'unknown',
25837+
'python_data_type': 'datetime',
2583825838
'python_description': 'Specifies the start time of the sync pulse.',
2583925839
'resettable': True,
2584025840
'type': 'CVIAbsoluteTime'
@@ -25904,7 +25904,7 @@
2590425904
'is_python_object': False,
2590525905
'name': 'FIRST_SAMP_TIMESTAMP_VAL',
2590625906
'python_class_name': 'Timing',
25907-
'python_data_type': 'unknown',
25907+
'python_data_type': 'datetime',
2590825908
'python_description': 'Indicates the timestamp of the first sample.',
2590925909
'resettable': False,
2591025910
'type': 'CVIAbsoluteTime'
@@ -25951,7 +25951,7 @@
2595125951
'is_python_object': False,
2595225952
'name': 'FIRST_SAMP_CLK_WHEN',
2595325953
'python_class_name': 'Timing',
25954-
'python_data_type': 'unknown',
25954+
'python_data_type': 'datetime',
2595525955
'python_description': 'Specifies the time of the first sample clock pulse.',
2595625956
'resettable': True,
2595725957
'type': 'CVIAbsoluteTime'
@@ -28948,9 +28948,10 @@
2894828948
'is_list': False,
2894928949
'is_python_object': False,
2895028950
'name': 'START_TRIG_TRIG_WHEN',
28951-
'python_class_name': 'TimeStartTrigger',
28952-
'python_data_type': 'unknown',
28951+
'python_class_name': 'StartTrigger',
28952+
'python_data_type': 'datetime',
2895328953
'python_description': 'Specifies when to trigger the start trigger.',
28954+
'python_name': 'trig_when',
2895428955
'resettable': True,
2895528956
'type': 'CVIAbsoluteTime'
2895628957
},
@@ -29433,7 +29434,7 @@
2943329434
'is_python_object': False,
2943429435
'name': 'REF_TRIG_TIMESTAMP_VAL',
2943529436
'python_class_name': 'ReferenceTrigger',
29436-
'python_data_type': 'unknown',
29437+
'python_data_type': 'datetime',
2943729438
'python_description': 'Indicates the reference trigger timestamp value.',
2943829439
'python_name': 'timestamp_val',
2943929440
'resettable': False,
@@ -29481,9 +29482,10 @@
2948129482
'is_list': False,
2948229483
'is_python_object': False,
2948329484
'name': 'ARM_START_TRIG_TRIG_WHEN',
29484-
'python_class_name': 'TimeArmStartTrigger',
29485-
'python_data_type': 'unknown',
29485+
'python_class_name': 'ArmStartTrigger',
29486+
'python_data_type': 'datetime',
2948629487
'python_description': 'Specifies when to trigger the arm start trigger.',
29488+
'python_name': 'trig_when',
2948729489
'resettable': True,
2948829490
'type': 'CVIAbsoluteTime'
2948929491
},
@@ -29554,7 +29556,7 @@
2955429556
'is_python_object': False,
2955529557
'name': 'ARM_START_TRIG_TIMESTAMP_VAL',
2955629558
'python_class_name': 'ArmStartTrigger',
29557-
'python_data_type': 'unknown',
29559+
'python_data_type': 'datetime',
2955829560
'python_description': 'Indicates the arm start trigger timestamp value.',
2955929561
'python_name': 'timestamp_val',
2956029562
'resettable': False,
@@ -29627,7 +29629,7 @@
2962729629
'is_python_object': False,
2962829630
'name': 'START_TRIG_TIMESTAMP_VAL',
2962929631
'python_class_name': 'StartTrigger',
29630-
'python_data_type': 'unknown',
29632+
'python_data_type': 'datetime',
2963129633
'python_description': 'Indicates the start trigger timestamp value.',
2963229634
'python_name': 'timestamp_val',
2963329635
'resettable': False,

src/codegen/templates/_grpc_interpreter.py.mako

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ from nidaqmx._stubs import nidaqmx_pb2 as grpc_types
3333
from nidaqmx._stubs import nidaqmx_pb2_grpc as nidaqmx_grpc
3434
from nidaqmx._stubs import session_pb2 as session_grpc_types
3535
from nidaqmx.error_codes import DAQmxErrors
36-
from nidaqmx._grpc_time import convert_time_to_timestamp
36+
from nidaqmx._grpc_time import convert_time_to_timestamp, convert_timestamp_to_time
3737

3838
_logger = logging.getLogger(__name__)
3939

src/codegen/utilities/attribute_helpers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import codegen.metadata as scrapigen_metadata
44
from codegen.properties.attribute import Attribute
55
from codegen.utilities.helpers import camel_to_snake_case
6-
from codegen.utilities.interpreter_helpers import INTERPRETER_CAMEL_TO_SNAKE_CASE_REGEXES
6+
from codegen.utilities.interpreter_helpers import (
7+
INTERPRETER_CAMEL_TO_SNAKE_CASE_REGEXES,
8+
)
79

810
EXCLUDED_ATTRIBUTES = [
911
"AI_CHAN_CAL_HAS_VALID_CAL_INFO",
@@ -228,6 +230,7 @@
228230
"int32[]": "int32_array",
229231
"uInt8[]": "bytes",
230232
"uInt32[]": "uint32_array",
233+
"CVIAbsoluteTime": "timestamp",
231234
}
232235

233236
GENERIC_ATTRIBUTE_GROUP_NAME_MAP = {

src/codegen/utilities/function_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def to_param_argtype(parameter):
197197
if parameter.ctypes_data_type == "ctypes.TaskHandle":
198198
return "lib_importer.task_handle"
199199
elif parameter.python_data_type == "datetime":
200-
return "_lib_time.AbsoluteTime"
200+
return "AbsoluteTime"
201201
elif parameter.direction == "in":
202202
# If is string input parameter, use separate custom
203203
# argtype to convert from unicode to bytes.

src/codegen/utilities/interpreter_helpers.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,12 @@
6464
"GetSyncPulseTimeWhen",
6565
"GetTimingAttributeExTimestamp",
6666
"GetTimingAttributeTimestamp",
67-
"GetTrigAttributeTimestamp",
6867
"SetArmStartTrigTrigWhen",
6968
"SetFirstSampClkWhen",
7069
"SetStartTrigTrigWhen",
7170
"SetSyncPulseTimeWhen",
7271
"SetTimingAttributeExTimestamp",
7372
"SetTimingAttributeTimestamp",
74-
"SetTrigAttributeTimestamp",
7573
"WaitForValidTimestamp",
7674
# Deprecated, not working
7775
"GetAnalogPowerUpStates",
@@ -173,13 +171,13 @@ def generate_interpreter_function_call_args(function_metadata):
173171
else:
174172
function_call_args.append(f"ctypes.byref({param.parameter_name})")
175173
elif param.direction == "in":
176-
if (
174+
if param.type == "CVIAbsoluteTime":
175+
function_call_args.append(f"AbsoluteTime.from_datetime({param.parameter_name})")
176+
elif (
177177
param.parameter_name == "value"
178178
and function_metadata.attribute_function_type == AttributeFunctionType.SET
179179
):
180180
function_call_args.append(type_cast_attribute_set_function_parameter(param))
181-
elif param.type == "CVIAbsoluteTime":
182-
function_call_args.append(f"AbsoluteTime.from_datetime({param.parameter_name})")
183181
else:
184182
function_call_args.append(param.parameter_name)
185183

@@ -258,6 +256,8 @@ def get_instantiation_lines_for_output(func):
258256
instantiation_lines.append(
259257
f"{param.parameter_name} = numpy.zeros(size, dtype={param.ctypes_data_type})"
260258
)
259+
elif param.type == "CVIAbsoluteTime":
260+
instantiation_lines.append(f"{param.parameter_name} = AbsoluteTime()")
261261
else:
262262
instantiation_lines.append(f"{param.parameter_name} = {param.ctypes_data_type}()")
263263
for param in get_interpreter_in_out_params(func):
@@ -447,7 +447,7 @@ def get_return_values(func):
447447
return_values.append(param.parameter_name)
448448
else:
449449
return_values.append(f"{param.parameter_name}.tolist()")
450-
elif param.type == "TaskHandle":
450+
elif param.type == "TaskHandle" or param.type == "CVIAbsoluteTime":
451451
return_values.append(param.parameter_name)
452452
else:
453453
return_values.append(f"{param.parameter_name}.value")
@@ -586,6 +586,8 @@ def get_response_parameters(func):
586586
response_parameters.append(f"response.{name}_raw")
587587
elif parameter.is_list:
588588
response_parameters.append(f"list(response.{name})")
589+
elif parameter.type == "CVIAbsoluteTime":
590+
response_parameters.append(f"convert_timestamp_to_time(response.{name})")
589591
else:
590592
response_parameters.append(f"response.{name}")
591593
return ", ".join(response_parameters)

0 commit comments

Comments
 (0)