Skip to content

Commit 337f010

Browse files
authored
Merge pull request #103 from carterturn/NIDAQmx-terminal-connecting
Allow arbitrary terminal connections for NI DAQmx devices
2 parents f23aca2 + 59fdf27 commit 337f010

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

docs/source/devices/ni_daqs.rst

+49
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,55 @@ Note that the counter connection is specified using the logical label `'ctr0'`.
105105
The physical wiring for this configuration would have port0/line0 wired directly to PFI9, with PFI1 being sent to the master pseudoclock retriggering system in case of timeout.
106106
If timeouts are not expected/represent experiment failure, this physical connection can be omitted.
107107

108+
In addition to their external ports, some types of NI DAQ modules (PXI, PXIe, CompactDAQ) feature internal ports, known as "terminals" in NI terminology.
109+
Terminals include most clocks and triggers in a module, as well as the external PFIN connections.
110+
The buffered and static digital IO connections are not terminals.
111+
Connections between terminals can be used for sharing clocks or triggers between modules in the same chassis (note: if sufficient clocklines and external inputs are available, it is likely preferable to simply use a unique clockline for each card).
112+
Within labscript, there are two methods for accessing this functionality.
113+
For sharing the clock input signal to other cards, the `clock_mirror_terminal` argument in the constructor can be specified. For example, in a system with two PXI-6733 analog cards in a PXI chassis (which supports 8 internal triggers, named `PXI_TrigN`), the connection table entries are
114+
115+
.. code-block:: python
116+
117+
NI_PXI_6733(name='dev_1',
118+
...,
119+
clock_terminal='/Dev1/PFI0',
120+
clock_mirror_terminal='/Dev1/PXI_Trig0',
121+
MAX_name='Dev1')
122+
123+
NI_PXI_6733(name='dev_2',
124+
...,
125+
clock_terminal='/Dev2/PXI_Trig0',
126+
MAX_name='Dev2')
127+
128+
However, some NI DAQ modules can not be clocked from certain terminal.
129+
To determine this, consult the `Device Routes` tab in NI MAX.
130+
If there is not a `Direct Route` or `Indirect Route` between the clock source and clock destination, the best option is to choose a different `clock_mirror_terminal` if possible.
131+
For some combinations of modules, there will be no pair of triggers linked to all the cards.
132+
To handle this situation, two triggers can be linked using the `connected_terminals` argument.
133+
This argument takes a list of tuples of terminal names, and connects the first terminal to the second terminal.
134+
For example, to share the clock in the previous with an additional PXIe-6535 digital card (which can not use `PXI_Trig0` as a clock), the connection table entries are
135+
136+
.. code-block:: python
137+
138+
NI_PXI_6733(name='dev_1',
139+
...,
140+
clock_terminal='/Dev1/PFI0',
141+
clock_mirror_terminal='/Dev1/PXI_Trig0',
142+
MAX_name='Dev1')
143+
144+
NI_PXI_6733(name='dev_2',
145+
...,
146+
clock_terminal='/Dev2/PXI_Trig0',
147+
MAX_name='Dev2')
148+
149+
NI_PXIe_6535(name='dev_3',
150+
...,
151+
clock_terminal='/Dev3/PXI_Trig7',
152+
MAX_name='Dev3',
153+
connected_terminals=[('/Dev3/PXI_Trig0', '/Dev3/PXI_Trig7')])
154+
155+
In addition to clocking, the `connected_terminals` argument can be used to link output terminals on an NI DAQ module to shared triggers, then link those shared triggers to input terminals of another NI DAQ module in the same chassis.
156+
108157

109158
Detailed Documentation
110159
~~~~~~~~~~~~~~~~~~~~~~

labscript_devices/NI_DAQmx/blacs_tabs.py

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ def initialise_GUI(self):
6666

6767
clock_terminal = properties['clock_terminal']
6868
clock_mirror_terminal = properties['clock_mirror_terminal']
69+
# get to avoid error on older connection tables
70+
connected_terminals = properties.get('connected_terminals', None)
6971
static_AO = properties['static_AO']
7072
static_DO = properties['static_DO']
7173
clock_limit = properties['clock_limit']

labscript_devices/NI_DAQmx/blacs_workers.py

+23
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,23 @@ def set_mirror_clock_terminal_connected(self, connected):
163163
else:
164164
DAQmxDisconnectTerms(self.clock_terminal, self.clock_mirror_terminal)
165165

166+
def set_connected_terminals_connected(self, connected):
167+
"""Connect the terminals in the connected terminals list.
168+
Allows on daisy chaining of the clock line to/from other devices
169+
that do not have a direct route (see Device Routes in NI MAX)."""
170+
if self.connected_terminals is None:
171+
return
172+
if connected:
173+
for terminal_pair in self.connected_terminals:
174+
DAQmxConnectTerms(
175+
terminal_pair[0],
176+
terminal_pair[1],
177+
DAQmx_Val_DoNotInvertPolarity,
178+
)
179+
else:
180+
for terminal_pair in self.connected_terminals:
181+
DAQmxDisconnectTerms(terminal_pair[0], terminal_pair[1])
182+
166183
def program_buffered_DO(self, DO_table):
167184
"""Create the DO task and program in the DO table for a shot. Return a
168185
dictionary of the final values of each channel in use"""
@@ -320,6 +337,9 @@ def transition_to_buffered(self, device_name, h5file, initial_values, fresh):
320337
# Mirror the clock terminal, if applicable:
321338
self.set_mirror_clock_terminal_connected(True)
322339

340+
# Mirror other terminals, if applicable
341+
self.set_connected_terminals_connected(True)
342+
323343
# Program the output tasks and retrieve the final values of each output:
324344
DO_final_values = self.program_buffered_DO(DO_table)
325345
AO_final_values = self.program_buffered_AO(AO_table)
@@ -372,6 +392,9 @@ def transition_to_manual(self, abort=False):
372392
# Remove the mirroring of the clock terminal, if applicable:
373393
self.set_mirror_clock_terminal_connected(False)
374394

395+
# Remove connections between other terminals, if applicable:
396+
self.set_connected_terminals_connected(False)
397+
375398
# Set up manual mode tasks again:
376399
self.start_manual_mode_tasks()
377400
if abort:

labscript_devices/NI_DAQmx/labscript_devices.py

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class NI_DAQmx(IntermediateDevice):
5858
"static_AO",
5959
"static_DO",
6060
"clock_mirror_terminal",
61+
"connected_terminals",
6162
"AI_range",
6263
"AI_start_delay",
6364
"AI_start_delay_ticks",
@@ -93,6 +94,7 @@ def __init__(
9394
static_AO=None,
9495
static_DO=None,
9596
clock_mirror_terminal=None,
97+
connected_terminals=None,
9698
acquisition_rate=None,
9799
AI_range=None,
98100
AI_range_Diff=None,
@@ -132,6 +134,9 @@ def __init__(
132134
clock_mirror_terminal (str, optional): Channel string of digital output
133135
that mirrors the input clock. Useful for daisy-chaning DAQs on the same
134136
clockline.
137+
connected_terminals (list, optional): List of pairs of strings of digital inputs
138+
and digital outputs that will be connected. Useful for daisy-chaining DAQs
139+
on the same clockline when they do not have direct routes (see Device Routes in NI MAX).
135140
acquisiton_rate (float, optional): Default sample rate of inputs.
136141
AI_range (iterable, optional): A `[Vmin, Vmax]` pair that sets the analog
137142
input voltage range for all analog inputs.

0 commit comments

Comments
 (0)