From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Multifunction DAQ

Showing results for 
Search instead for 
Did you mean: 

Python Synchronization of multiple analog inputs CDAQ-9185

Go to solution



I have been using the Python nidaqmax package to simultaneously acquire analog inputs from two NI9239 (BNC) plugged into a cDAQ9185. 

My issue is that I am not managing to use the same clock for all the channels to synchronize my measurements. 


The code worked fine when using the internal clock of each of the NI9239 respectively ( i.e in the code replacing the underlined lines with  source = "/cDAQ9185-213AB07Mod1/ai/SampleClock" in task A, and  source = "/cDAQ9185-213AB07Mod2/ai/SampleClock" in task B). 


However, when using one of the cDAQ9185 clock as a common clock (as in the code below), the code returned errors. The different sources can be seen in the attached screenshot of the NIMAX software. I have also tried using "/cDAQ9185-213AB07/80MHzTimebase" without success.


Another attempt consisted in using the internal clock of one of the module as the common clock as it seems to be the case in: Résolu : Python multi-tasking using cfg_samp_clk_timing question - NI Community  ( i.e in the code replacing the underlined lines with  source = "/cDAQ9185-213AB07Mod1/ai/SampleClock" in task A, and  source = "/cDAQ9185-213AB07Mod1/ai/SampleClock" in task B). But this also returned errors.


Any help to achieve this synchronisation would be much appreciated. 


Here is my code below: 


import nidaqmx
npnts = int( fs_acq * duration) # number of sample per acquisition
 with nidaqmx.Task() as a_task, nidaqmx.Task() as b_task:
# Create analog input DAQmx Task from  NI9239 A (module 1)
, name_to_assign_to_channel="hotwireA"min_val=-10, max_val=10)
 # Create analog input DAQmx Task from  NI9239 B (module 2)
, name_to_assign_to_channel="hotwireB",min_val=-10, max_val=10)
# Configure timing for ai task module A
 a_task.timing.cfg_samp_clk_timing(rate=fs_acq, source = "/cDAQ9185-213AB07/ai/SampleClock", sample_mode = nidaqmx.constants.AcquisitionType.FINITE,samps_per_chan = npnts
 b_task.timing.cfg_samp_clk_timing(rate=fs_acq, source = "/cDAQ9185-213AB07/ai/SampleClock",  sample_mode = nidaqmx.constants.AcquisitionType.FINITE,samps_per_chan=npnts ) # you may not need samps_per_chan

a_task.start() # start performing the task
"name": "DaqError",
"message": "Requested sample clock source is invalid.\nProperty: DAQmx_SampClk_Src\nCorresponding Value: /cDAQ9185-213AB07Mod1/SampleClock\n\nDevice: cDAQ9185-213AB07\n\nTask Name: _unnamedTask<2>\n\nStatus Code: -200414",
0 Kudos
Message 1 of 3
Accepted by topic author MarilouJourdain

You can use channel expansion and add multiple channels into a single task. DAQmx driver will handle the timing routing for you.


import nidaqmx
npnts = int( fs_acq * duration) # number of sample per acquisition
 with nidaqmx.Task() as task
# Add channels from NI9239 A (module 1)
, name_to_assign_to_channel="hotwireA", min_val=-10, max_val=10)
 # Add channels from NI9239 B (module 2)
, name_to_assign_to_channel="hotwireB",min_val=-10, max_val=10)
# Configure timing
task.timing.cfg_samp_clk_timing(rate=fs_acq, sample_mode = nidaqmx.constants.AcquisitionType.FINITE,samps_per_chan = npnts ) 
task.start() # start performing the task
Message 2 of 3

Thank you for your prompt reply. This worked perfectly, thank you !! 

0 Kudos
Message 3 of 3