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 "When" attribute to start_trigger.py #481

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 8 additions & 0 deletions generated/nidaqmx/_base_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,10 @@ def get_trig_attribute_int32_array(self, task, attribute):
def get_trig_attribute_string(self, task, attribute):
raise NotImplementedError

@abc.abstractmethod
def get_trig_attribute_timestamp(self, task, attribute):
raise NotImplementedError

@abc.abstractmethod
def get_trig_attribute_uint32(self, task, attribute):
raise NotImplementedError
Expand Down Expand Up @@ -1572,6 +1576,10 @@ def set_trig_attribute_int32_array(self, task, attribute, value):
def set_trig_attribute_string(self, task, attribute, value):
raise NotImplementedError

@abc.abstractmethod
def set_trig_attribute_timestamp(self, task, attribute, value):
raise NotImplementedError

@abc.abstractmethod
def set_trig_attribute_uint32(self, task, attribute, value):
raise NotImplementedError
Expand Down
15 changes: 14 additions & 1 deletion generated/nidaqmx/_grpc_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +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
from nidaqmx._grpc_time import convert_time_to_timestamp, convert_timestamp_to_time

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -2180,6 +2180,12 @@ def get_trig_attribute_string(self, task, attribute):
grpc_types.GetTrigAttributeStringRequest(task=task, attribute_raw=attribute))
return response.value

def get_trig_attribute_timestamp(self, task, attribute):
response = self._invoke(
self._client.GetTrigAttributeTimestamp,
grpc_types.GetTrigAttributeTimestampRequest(task=task, attribute_raw=attribute))
return convert_timestamp_to_time(response.value)

def get_trig_attribute_uint32(self, task, attribute):
response = self._invoke(
self._client.GetTrigAttributeUInt32,
Expand Down Expand Up @@ -3126,6 +3132,13 @@ def set_trig_attribute_string(self, task, attribute, value):
grpc_types.SetTrigAttributeStringRequest(
task=task, attribute_raw=attribute, value=value))

def set_trig_attribute_timestamp(self, task, attribute, value):
response = self._invoke(
self._client.SetTrigAttributeTimestamp,
grpc_types.SetTrigAttributeTimestampRequest(
task=task, attribute_raw=attribute,
value=convert_time_to_timestamp(value)))

def set_trig_attribute_uint32(self, task, attribute, value):
response = self._invoke(
self._client.SetTrigAttributeUInt32,
Expand Down
30 changes: 28 additions & 2 deletions generated/nidaqmx/_library_interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,7 @@ def cfg_time_start_trig(self, task, when, timescale):
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
lib_importer.task_handle, _lib_time.AbsoluteTime,
ctypes.c_int]
lib_importer.task_handle, AbsoluteTime, ctypes.c_int]

error_code = cfunc(
task, AbsoluteTime.from_datetime(when), timescale)
Expand Down Expand Up @@ -3672,6 +3671,21 @@ def get_trig_attribute_string(self, task, attribute):
self.check_for_error(size_or_code)
return value.value.decode('ascii')

def get_trig_attribute_timestamp(self, task, attribute):
value = AbsoluteTime()

cfunc = lib_importer.cdll.DAQmxGetTrigAttribute
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
lib_importer.task_handle, ctypes.c_int32]

error_code = cfunc(
task, attribute, ctypes.byref(value))
self.check_for_error(error_code)
return value

def get_trig_attribute_uint32(self, task, attribute):
value = ctypes.c_uint32()

Expand Down Expand Up @@ -5333,6 +5347,18 @@ def set_trig_attribute_string(self, task, attribute, value):
task, attribute, value.encode('ascii'))
self.check_for_error(error_code)

def set_trig_attribute_timestamp(self, task, attribute, value):
cfunc = lib_importer.cdll.DAQmxSetTrigAttribute
if cfunc.argtypes is None:
with cfunc.arglock:
if cfunc.argtypes is None:
cfunc.argtypes = [
lib_importer.task_handle, ctypes.c_int32]

error_code = cfunc(
task, attribute, AbsoluteTime.from_datetime(value))
self.check_for_error(error_code)

def set_trig_attribute_uint32(self, task, attribute, value):
cfunc = lib_importer.cdll.DAQmxSetTrigAttribute
if cfunc.argtypes is None:
Expand Down
17 changes: 17 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 @@ -832,6 +832,23 @@ def retriggerable(self, val):
def retriggerable(self):
self._interpreter.reset_trig_attribute(self._handle, 0x190f)

@property
def start_trig_trig_when(self):
DeborahOoi96 marked this conversation as resolved.
Show resolved Hide resolved
"""
datetime: Specifies when to trigger the start trigger.
"""

val = self._interpreter.get_trig_attribute_timestamp(self._handle, 0x304d)
return val

@start_trig_trig_when.setter
def start_trig_trig_when(self, val):
self._interpreter.set_trig_attribute_timestamp(self._handle, 0x304d, val)

@start_trig_trig_when.deleter
def start_trig_trig_when(self):
self._interpreter.reset_trig_attribute(self._handle, 0x304d)

@property
def term(self):
"""
Expand Down
22 changes: 12 additions & 10 deletions src/codegen/metadata/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25834,7 +25834,7 @@
'is_python_object': False,
'name': 'SYNC_PULSE_TIME_WHEN',
'python_class_name': 'Timing',
'python_data_type': 'unknown',
'python_data_type': 'datetime',
'python_description': 'Specifies the start time of the sync pulse.',
'resettable': True,
'type': 'CVIAbsoluteTime'
Expand Down Expand Up @@ -25904,7 +25904,7 @@
'is_python_object': False,
'name': 'FIRST_SAMP_TIMESTAMP_VAL',
'python_class_name': 'Timing',
'python_data_type': 'unknown',
'python_data_type': 'datetime',
'python_description': 'Indicates the timestamp of the first sample.',
'resettable': False,
'type': 'CVIAbsoluteTime'
Expand Down Expand Up @@ -25951,7 +25951,7 @@
'is_python_object': False,
'name': 'FIRST_SAMP_CLK_WHEN',
'python_class_name': 'Timing',
'python_data_type': 'unknown',
'python_data_type': 'datetime',
'python_description': 'Specifies the time of the first sample clock pulse.',
'resettable': True,
'type': 'CVIAbsoluteTime'
Expand Down Expand Up @@ -28948,9 +28948,10 @@
'is_list': False,
'is_python_object': False,
'name': 'START_TRIG_TRIG_WHEN',
'python_class_name': 'TimeStartTrigger',
'python_data_type': 'unknown',
'python_class_name': 'StartTrigger',
'python_data_type': 'datetime',
bkeryan marked this conversation as resolved.
Show resolved Hide resolved
'python_description': 'Specifies when to trigger the start trigger.',
'python_name': 'trig_when',
'resettable': True,
'type': 'CVIAbsoluteTime'
},
Expand Down Expand Up @@ -29433,7 +29434,7 @@
'is_python_object': False,
'name': 'REF_TRIG_TIMESTAMP_VAL',
'python_class_name': 'ReferenceTrigger',
'python_data_type': 'unknown',
'python_data_type': 'datetime',
'python_description': 'Indicates the reference trigger timestamp value.',
'python_name': 'timestamp_val',
'resettable': False,
Expand Down Expand Up @@ -29481,9 +29482,10 @@
'is_list': False,
'is_python_object': False,
'name': 'ARM_START_TRIG_TRIG_WHEN',
'python_class_name': 'TimeArmStartTrigger',
'python_data_type': 'unknown',
'python_class_name': 'ArmStartTrigger',
'python_data_type': 'datetime',
'python_description': 'Specifies when to trigger the arm start trigger.',
'python_name': 'trig_when',
'resettable': True,
'type': 'CVIAbsoluteTime'
},
Expand Down Expand Up @@ -29554,7 +29556,7 @@
'is_python_object': False,
'name': 'ARM_START_TRIG_TIMESTAMP_VAL',
'python_class_name': 'ArmStartTrigger',
'python_data_type': 'unknown',
'python_data_type': 'datetime',
'python_description': 'Indicates the arm start trigger timestamp value.',
'python_name': 'timestamp_val',
'resettable': False,
Expand Down Expand Up @@ -29627,7 +29629,7 @@
'is_python_object': False,
'name': 'START_TRIG_TIMESTAMP_VAL',
'python_class_name': 'StartTrigger',
'python_data_type': 'unknown',
'python_data_type': 'datetime',
'python_description': 'Indicates the start trigger timestamp value.',
'python_name': 'timestamp_val',
'resettable': False,
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/templates/_grpc_interpreter.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +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
from nidaqmx._grpc_time import convert_time_to_timestamp, convert_timestamp_to_time

_logger = logging.getLogger(__name__)

Expand Down
5 changes: 4 additions & 1 deletion src/codegen/utilities/attribute_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import codegen.metadata as scrapigen_metadata
from codegen.properties.attribute import Attribute
from codegen.utilities.helpers import camel_to_snake_case
from codegen.utilities.interpreter_helpers import INTERPRETER_CAMEL_TO_SNAKE_CASE_REGEXES
from codegen.utilities.interpreter_helpers import (
INTERPRETER_CAMEL_TO_SNAKE_CASE_REGEXES,
)

EXCLUDED_ATTRIBUTES = [
"AI_CHAN_CAL_HAS_VALID_CAL_INFO",
Expand Down Expand Up @@ -228,6 +230,7 @@
"int32[]": "int32_array",
"uInt8[]": "bytes",
"uInt32[]": "uint32_array",
"CVIAbsoluteTime": "timestamp",
}

GENERIC_ATTRIBUTE_GROUP_NAME_MAP = {
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/utilities/function_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "_lib_time.AbsoluteTime"
return "AbsoluteTime"
elif parameter.direction == "in":
# If is string input parameter, use separate custom
# argtype to convert from unicode to bytes.
Expand Down
14 changes: 8 additions & 6 deletions src/codegen/utilities/interpreter_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,12 @@
"GetSyncPulseTimeWhen",
"GetTimingAttributeExTimestamp",
"GetTimingAttributeTimestamp",
"GetTrigAttributeTimestamp",
DeborahOoi96 marked this conversation as resolved.
Show resolved Hide resolved
"SetArmStartTrigTrigWhen",
"SetFirstSampClkWhen",
"SetStartTrigTrigWhen",
"SetSyncPulseTimeWhen",
"SetTimingAttributeExTimestamp",
"SetTimingAttributeTimestamp",
DeborahOoi96 marked this conversation as resolved.
Show resolved Hide resolved
"SetTrigAttributeTimestamp",
"WaitForValidTimestamp",
# Deprecated, not working
"GetAnalogPowerUpStates",
Expand Down Expand Up @@ -173,13 +171,13 @@ def generate_interpreter_function_call_args(function_metadata):
else:
function_call_args.append(f"ctypes.byref({param.parameter_name})")
elif param.direction == "in":
if (
if param.type == "CVIAbsoluteTime":
function_call_args.append(f"AbsoluteTime.from_datetime({param.parameter_name})")
elif (
param.parameter_name == "value"
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 @@ -258,6 +256,8 @@ def get_instantiation_lines_for_output(func):
instantiation_lines.append(
f"{param.parameter_name} = numpy.zeros(size, dtype={param.ctypes_data_type})"
)
elif param.type == "CVIAbsoluteTime":
instantiation_lines.append(f"{param.parameter_name} = AbsoluteTime()")
else:
instantiation_lines.append(f"{param.parameter_name} = {param.ctypes_data_type}()")
for param in get_interpreter_in_out_params(func):
Expand Down Expand Up @@ -447,7 +447,7 @@ def get_return_values(func):
return_values.append(param.parameter_name)
else:
return_values.append(f"{param.parameter_name}.tolist()")
elif param.type == "TaskHandle":
elif param.type == "TaskHandle" or param.type == "CVIAbsoluteTime":
return_values.append(param.parameter_name)
else:
return_values.append(f"{param.parameter_name}.value")
Expand Down Expand Up @@ -586,6 +586,8 @@ def get_response_parameters(func):
response_parameters.append(f"response.{name}_raw")
elif parameter.is_list:
response_parameters.append(f"list(response.{name})")
elif parameter.type == "CVIAbsoluteTime":
response_parameters.append(f"convert_timestamp_to_time(response.{name})")
else:
response_parameters.append(f"response.{name}")
return ", ".join(response_parameters)
Expand Down
Loading