From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Python Synchronization of multiple analog inputs CDAQ-9185

Solved!
Go to solution

Hi,

 

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)
 a_task.ai_channels.add_ai_voltage_chan(
"cDAQ9185-213AB07Mod1/ai0:2"
, name_to_assign_to_channel="hotwireA"min_val=-10, max_val=10)
 
 # Create analog input DAQmx Task from  NI9239 B (module 2)
b_task.ai_channels.add_ai_voltage_chan(
"cDAQ9185-213AB07Mod2/ai0: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
b_task.start()
 
 a_task.wait_until_done()
b_task.wait_until_done()
 
-----------------------------------------------------------------------------------------------------------------------------------------------------
 
Error: 
"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
(797 Views)
Solution
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)
 task.ai_channels.add_ai_voltage_chan(
"cDAQ9185-213AB07Mod1/ai0:2"
, name_to_assign_to_channel="hotwireA", min_val=-10, max_val=10)
 
 # Add channels from NI9239 B (module 2)
task.ai_channels.add_ai_voltage_chan(
"cDAQ9185-213AB07Mod2/ai0: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
task.wait_until_done()
Message 2 of 3
(778 Views)

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

0 Kudos
Message 3 of 3
(717 Views)