Skip to content

Commit fa1edc1

Browse files
NI-DAQmx-wait-changes: move wait monitor error checking to compilation time, and ensure that
start_order and stop_order of separate wait monitor timeout and acquisition devices are configured as required to ensure that the subprocess otherwise belonging to the acquisition device will be able to control the timeout device without contention from tasks in the other process.
1 parent 31709a0 commit fa1edc1

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

NI_DAQmx/blacs_tabs.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,20 +158,14 @@ def initialise_GUI(self):
158158
if wait_acq_device == self.device_name:
159159
if wait_timeout_device:
160160
wait_timeout_device = connection_table.find_by_name(wait_timeout_device)
161-
if not hasattr(models, wait_timeout_device.device_class):
162-
msg = """If using an NI DAQmx device as a wait monitor input, then
163-
the wait monitor timeout device must also be an NI DAQmx device,
164-
not {}.""".format(
165-
wait_timeout_device.device_class
166-
)
167-
raise RuntimeError(dedent(msg))
168161
wait_timeout_MAX_name = wait_timeout_device.properties['MAX_name']
169162
else:
170163
wait_timeout_MAX_name = None
171164

172165
if num_CI == 0:
173-
msg = "Device cannot be a wait monitor as it has no counter inputs"
174-
raise RuntimeError(msg)
166+
msg = """Device cannot be the wait monitor acquisiiton device as it has
167+
no counter inputs"""
168+
raise RuntimeError(dedent(msg))
175169

176170
self.create_worker(
177171
"wait_monitor_worker",

NI_DAQmx/labscript_devices.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,49 @@ def _make_analog_input_table(self, inputs):
404404

405405
return acquisition_table
406406

407+
def _check_wait_monitor_timeout_device_config(self):
408+
"""Check that if we are the wait monitor acquisition device and another device
409+
is the wait monitor timeout device, that a) the other device is a DAQmx device
410+
and b) the other device has a start_order lower than us and a stop_order higher
411+
than us."""
412+
acquisition_device = compiler.wait_monitor.acquisition_device
413+
timeout_device = compiler.wait_monitor.timeout_device
414+
if acquisition_device is not self or timeout_device is None:
415+
return
416+
if timeout_device is self:
417+
return
418+
if not isinstance(timeout_device, NI_DAQmx):
419+
msg = """If using an NI DAQmx device as a wait monitor acquisition device,
420+
then the wait monitor timeout device must also be an NI DAQmx device,
421+
not {}."""
422+
raise TypeError(dedent(msg).format(type(timeout_device)))
423+
timeout_start = timeout_device.start_order
424+
if timeout_start is None:
425+
timeout_start = 0
426+
timeout_stop = timeout_device.stop_order
427+
if timeout_stop is None:
428+
timeout_stop = 0
429+
self_start = self.start_order
430+
if self_start is None:
431+
self_start = 0
432+
self_stop = self.stop_order
433+
if self_stop is None:
434+
self_stop = 0
435+
if timeout_start >= self_start or timeout_stop <= self_stop:
436+
msg = """If using different DAQmx devices as the wait monitor acquisition
437+
and timeout devices, the timeout device must transition_to_buffered
438+
before the acquisition device, and transition_to_manual after it, in
439+
order to ensure the output port for timeout pulses is not in use (by the
440+
manual mode DO task) when the wait monitor subprocess attempts to use
441+
it. To achieve this, pass the start_order and stop_order keyword
442+
arguments to the devices in your connection table, ensuring that the
443+
timeout device has a lower start_order and a higher stop_order than the
444+
acquisition device. The default start_order and stop_order is zero, so
445+
if you are not otherwise controlling the order that devices are
446+
programmed, you can set start_order=-1, stop_order=1 on the timeout
447+
device only."""
448+
raise RuntimeError(dedent(msg))
449+
407450
def generate_code(self, hdf5_file):
408451
IntermediateDevice.generate_code(self, hdf5_file)
409452
analogs = {}
@@ -438,6 +481,7 @@ def generate_code(self, hdf5_file):
438481
AI_table = self._make_analog_input_table(inputs)
439482

440483
self._check_AI_not_too_fast(AI_table)
484+
self._check_wait_monitor_timeout_device_config()
441485

442486
grp = self.init_device_group(hdf5_file)
443487
if AO_table is not None:

0 commit comments

Comments
 (0)