Skip to content

Commit fdc318b

Browse files
authored
Updating FGEN example to catch timeout and maximum time exceeded exce… (#211)
* Updating FGEN example to catch timeout and maximum time exceeded exceptions when calling wait_until_done. Signed-off-by: Chris Delpire <chris.delpire@ni.com> * Updating error code names and merging if and elif statements. Signed-off-by: Chris Delpire <chris.delpire@ni.com> * Undoing change style tool made. Signed-off-by: Chris Delpire <chris.delpire@ni.com> Signed-off-by: Chris Delpire <chris.delpire@ni.com>
1 parent 4cbb656 commit fdc318b

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

examples/nifgen_standard_function/measurement.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
import ni_measurementlink_service as nims
1717

18+
NIFGEN_OPERATION_TIMED_OUT_ERROR_CODE = -1074098044
19+
NIFGEN_MAX_TIME_EXCEEDED_ERROR_CODE = -1074118637
20+
1821
measurement_info = nims.MeasurementInfo(
1922
display_name="NI-FGEN Standard Function (Py)",
2023
version="0.1.0.0",
@@ -138,7 +141,23 @@ def cancel_callback():
138141
if is_simulated:
139142
time.sleep(sleep_time)
140143
else:
141-
sessions[0].wait_until_done(hightime.timedelta(seconds=sleep_time))
144+
try:
145+
sessions[0].wait_until_done(hightime.timedelta(seconds=sleep_time))
146+
except nifgen.Error as e:
147+
"""
148+
There is no native way to support cancellation when generating a waveform.
149+
To support cancellation, we will be calling wait_until_done
150+
until it succeeds or we have gone past the specified timeout. wait_until_done
151+
will throw an exception if it times out, which is why we are catching
152+
and doing nothing.
153+
"""
154+
if (
155+
e.code == NIFGEN_OPERATION_TIMED_OUT_ERROR_CODE
156+
or e.code == NIFGEN_MAX_TIME_EXCEEDED_ERROR_CODE
157+
):
158+
pass
159+
else:
160+
raise
142161

143162
return ()
144163

0 commit comments

Comments
 (0)