Skip to content

Commit 7f0c6fe

Browse files
authored
Fix first_samp_timestamp_val property does not work due to missing method in LibraryInterpreter (#857)
* uncomment gettimingattritimestamp * update test * create tests for first_samp_clk_when * uncomment gettimingattritimestamp * update test * create tests for first_samp_clk_when * Merge branch 'users/yelau/fix_first_samp_timestamp_val_not_working' of https://github.com/lau-yeexuan/nidaqmx-python into users/yelau/fix_first_samp_timestamp_val_not_working * fix lint * test for first_samp_timestamp_val * fix lint * Uncomment GetTimingAttributeTimestamp from Ignored Functions * changelod * resolve comment * fix merge * resolve comment * fix lint
1 parent 5c22f3a commit 7f0c6fe

File tree

6 files changed

+57
-1
lines changed

6 files changed

+57
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ All notable changes to this project will be documented in this file.
3030

3131
* ### Resolved Issues
3232
* [843: read methods use task.in_stream.channels_to_read, which is slow](https://github.com/ni/nidaqmx-python/issues/843)
33+
* [639: first_samp_timestamp_val property does not work because LibraryInterpreter is missing a method](https://github.com/ni/nidaqmx-python/issues/639)
3334

3435
* ### Major Changes
3536
* (IN PROGRESS behind "WAVEFORM_SUPPORT" feature toggle) Added support for reading and writing Waveform data.

generated/nidaqmx/_base_interpreter.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,10 @@ def get_timing_attribute_int32(self, task, attribute):
10931093
def get_timing_attribute_string(self, task, attribute):
10941094
raise NotImplementedError
10951095

1096+
@abc.abstractmethod
1097+
def get_timing_attribute_timestamp(self, task, attribute):
1098+
raise NotImplementedError
1099+
10961100
@abc.abstractmethod
10971101
def get_timing_attribute_uint32(self, task, attribute):
10981102
raise NotImplementedError

generated/nidaqmx/_grpc_interpreter.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,6 +2181,12 @@ def get_timing_attribute_string(self, task, attribute):
21812181
grpc_types.GetTimingAttributeStringRequest(task=task, attribute_raw=attribute))
21822182
return response.value
21832183

2184+
def get_timing_attribute_timestamp(self, task, attribute):
2185+
response = self._invoke(
2186+
self._client.GetTimingAttributeTimestamp,
2187+
grpc_types.GetTimingAttributeTimestampRequest(task=task, attribute_raw=attribute))
2188+
return convert_timestamp_to_time(response.value)
2189+
21842190
def get_timing_attribute_uint32(self, task, attribute):
21852191
response = self._invoke(
21862192
self._client.GetTimingAttributeUInt32,

generated/nidaqmx/_library_interpreter.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3730,6 +3730,21 @@ def get_timing_attribute_string(self, task, attribute):
37303730
self.check_for_error(size_or_code)
37313731
return value.value.decode(lib_importer.encoding)
37323732

3733+
def get_timing_attribute_timestamp(self, task, attribute):
3734+
value = AbsoluteTime()
3735+
3736+
cfunc = lib_importer.cdll.DAQmxGetTimingAttribute
3737+
if cfunc.argtypes is None:
3738+
with cfunc.arglock:
3739+
if cfunc.argtypes is None:
3740+
cfunc.argtypes = [
3741+
lib_importer.task_handle, ctypes.c_int32]
3742+
3743+
error_code = cfunc(
3744+
task, attribute, ctypes.byref(value))
3745+
self.check_for_error(error_code)
3746+
return value.to_datetime()
3747+
37333748
def get_timing_attribute_uint32(self, task, attribute):
37343749
value = ctypes.c_uint32()
37353750

src/codegen/utilities/interpreter_helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
"SetRealTimeAttributeUInt32",
4545
"WaitForNextSampleClock",
4646
# Time triggers
47+
# Single-attribute get/set functions are not used
48+
# Generic Get/SetTimingAttribute{Type} functions are used instead
4749
"GetArmStartTrigTimestampVal",
4850
"GetArmStartTrigTrigWhen",
4951
"GetFirstSampClkWhen",
@@ -53,7 +55,6 @@
5355
"GetStartTrigTrigWhen",
5456
"GetSyncPulseTimeWhen",
5557
"GetTimingAttributeExTimestamp",
56-
"GetTimingAttributeTimestamp",
5758
"SetArmStartTrigTrigWhen",
5859
"SetFirstSampClkWhen",
5960
"SetStartTrigTrigWhen",

tests/component/task/test_timing_properties.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from datetime import datetime as std_datetime
2+
13
import pytest
24

35
from nidaqmx import DaqError
@@ -470,3 +472,30 @@ def test___timing___set_unint64_property_out_of_range_value___throws_daqerror(
470472
with pytest.raises(DaqError) as e:
471473
_ = task.timing.samp_quant_samp_per_chan
472474
assert e.value.error_type == DAQmxErrors.INVALID_ATTRIBUTE_VALUE
475+
476+
477+
def test___timing___get_timestamp_property___returns_value(task, sim_9205_device):
478+
task.ai_channels.add_ai_voltage_chan(sim_9205_device.ai_physical_chans[0].name)
479+
task.timing.cfg_samp_clk_timing(1000, samps_per_chan=100)
480+
481+
task.start()
482+
timestamp = task.timing.first_samp_timestamp_val
483+
484+
assert isinstance(timestamp, std_datetime)
485+
486+
task.stop()
487+
488+
489+
def test___timing___get_timestamp_property_with_device_context___throws_daqerror(
490+
task, sim_9205_device
491+
):
492+
task.ai_channels.add_ai_voltage_chan(sim_9205_device.ai_physical_chans[0].name)
493+
task.timing.cfg_samp_clk_timing(1000, samps_per_chan=100)
494+
task.start()
495+
496+
with pytest.raises(DaqError) as e:
497+
_ = task.timing[sim_9205_device].first_samp_timestamp_val
498+
499+
assert e.value.error_type == DAQmxErrors.M_STUDIO_OPERATION_DOES_NOT_SUPPORT_DEVICE_CONTEXT
500+
501+
task.stop()

0 commit comments

Comments
 (0)