LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read mutiple channels simultaneously in vc++

Previously, I create a task to read 6 channels in vc++. The method I use is reading eatch channel separately. Here, problem rising! One channel take one second, and six is six seconds. It's too long to my control system. So I want to read them simultaneously. One sulotion I know is using multithreading, but I dont think it is the best. I believe there are other sulotions in DAQmx.

 

Here is the main code i use now:

 

DAQmxCreateTask("",&DAQtask);
DAQmxCreateAIVoltageChan(DAQtask,"Dev1/ai0:5","",DAQmx_Val_Cfg_Default,-5.0,5.0,DAQmx_Val_Volts,NULL);

DAQmxCfgSampClkTiming(DAQtask,"",1000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,N);

 

DAQmxStartTask(DAQtask);
DAQmxSetReadChannelsToRead(DAQtask, "Dev1/ai0");
DAQmxReadAnalogF64(DAQtask,-1,10.0,DAQmx_Val_GroupByChannel,OriginData1,N,&read1,NULL);
DAQmxStopTask(DAQtask);

 

DAQmxStartTask(DAQtask);
DAQmxSetReadChannelsToRead(DAQtask, "Dev1/ai1");
DAQmxReadAnalogF64(DAQtask,-1,10.0,DAQmx_Val_GroupByChannel,OriginData2,N,&read2,NULL);
DAQmxStopTask(DAQtask);

 

DAQmxStartTask(DAQtask);
DAQmxSetReadChannelsToRead(DAQtask, "Dev1/ai2");
DAQmxReadAnalogF64(DAQtask,-1,10.0,DAQmx_Val_GroupByChannel,OriginData3,N,&read3,NULL);
DAQmxStopTask(DAQtask);

DAQmxStartTask(DAQtask);
DAQmxSetReadChannelsToRead(DAQtask, "Dev1/ai3");
DAQmxReadAnalogF64(DAQtask,-1,10.0,DAQmx_Val_GroupByChannel,OriginData4,N,&read4,NULL);
DAQmxStopTask(DAQtask);

 

DAQmxStartTask(DAQtask);
DAQmxSetReadChannelsToRead(DAQtask, "Dev1/ai4");
DAQmxReadAnalogF64(DAQtask,-1,10.0,DAQmx_Val_GroupByChannel,OriginData5,N,&read5,NULL);
DAQmxStopTask(DAQtask);

 

DAQmxStartTask(DAQtask);
DAQmxSetReadChannelsToRead(DAQtask, "Dev1/ai5");
DAQmxReadAnalogF64(DAQtask,-1,10.0,DAQmx_Val_GroupByChannel,OriginData6,N,&read6,NULL);
DAQmxStopTask(DAQtask);

 

DAQmxClearTask(DAQtask);

 

Thank you for your reply!

 

0 Kudos
Message 1 of 9
(3,615 Views)

The board I use is PCI 6221. I'm afread the multithread cannot work...

0 Kudos
Message 2 of 9
(3,608 Views)

Since you posted in the LabVIEW forum, please explain how the question is related to LabVIEW. I don't quite see it.

0 Kudos
Message 3 of 9
(2,190 Views)

This is almost trivial to do in LabVIEW using DAQmx.  Depending on what you want to do with the data from the six (simultaneously-acquired) Analog channels, you could probably use 3 or 4 DAQmx functions, a While loop, a Stop Control, and maybe a Chart.

 

Bob Schor

0 Kudos
Message 4 of 9
(2,178 Views)

@EdwardNewGaite wrote:

Previously, I create a task to read 6 channels in vc++. The method I use is reading eatch channel separately. Here, problem rising! One channel take one second, and six is six seconds. It's too long to my control system. So I want to read them simultaneously. One sulotion I know is using multithreading, but I dont think it is the best. I believe there are other sulotions in DAQmx.

 

Here is the main code i use now:

 

DAQmxCreateTask("",&DAQtask);
DAQmxCreateAIVoltageChan(DAQtask,"Dev1/ai0:5","",DAQmx_Val_Cfg_Default,-5.0,5.0,DAQmx_Val_Volts,NULL);

DAQmxCfgSampClkTiming(DAQtask,"",1000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,N);

 

DAQmxStartTask(DAQtask);
DAQmxSetReadChannelsToRead(DAQtask, "Dev1/ai0");
DAQmxReadAnalogF64(DAQtask,-1,10.0,DAQmx_Val_GroupByChannel,OriginData1,N,&read1,NULL);
DAQmxStopTask(DAQtask);

 

DAQmxStartTask(DAQtask);
DAQmxSetReadChannelsToRead(DAQtask, "Dev1/ai1");
DAQmxReadAnalogF64(DAQtask,-1,10.0,DAQmx_Val_GroupByChannel,OriginData2,N,&read2,NULL);
DAQmxStopTask(DAQtask);

 

DAQmxStartTask(DAQtask);
DAQmxSetReadChannelsToRead(DAQtask, "Dev1/ai2");
DAQmxReadAnalogF64(DAQtask,-1,10.0,DAQmx_Val_GroupByChannel,OriginData3,N,&read3,NULL);
DAQmxStopTask(DAQtask);

DAQmxStartTask(DAQtask);
DAQmxSetReadChannelsToRead(DAQtask, "Dev1/ai3");
DAQmxReadAnalogF64(DAQtask,-1,10.0,DAQmx_Val_GroupByChannel,OriginData4,N,&read4,NULL);
DAQmxStopTask(DAQtask);

 

DAQmxStartTask(DAQtask);
DAQmxSetReadChannelsToRead(DAQtask, "Dev1/ai4");
DAQmxReadAnalogF64(DAQtask,-1,10.0,DAQmx_Val_GroupByChannel,OriginData5,N,&read5,NULL);
DAQmxStopTask(DAQtask);

 

DAQmxStartTask(DAQtask);
DAQmxSetReadChannelsToRead(DAQtask, "Dev1/ai5");
DAQmxReadAnalogF64(DAQtask,-1,10.0,DAQmx_Val_GroupByChannel,OriginData6,N,&read6,NULL);
DAQmxStopTask(DAQtask);

 

DAQmxClearTask(DAQtask);

 

Thank you for your reply!

 


The technique is to put all 6 channels in the same task, and use read/write N channels function with that multi-channel task.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution
0 Kudos
Message 5 of 9
(2,171 Views)

Hi,

 

you all answered a 9 year old thread… 😄

 

(I guess this was triggered by a SPAM message, which is already removed by now.)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 9
(2,157 Views)

@GerdW wrote:

Hi,

 

you all answered a 9 year old thread… 😄

 

(I guess this was triggered by a SPAM message, which is already removed by now.)


Actually, they just posted in the version conversion forum, after which I looked at the profile and saw some unread messages, then assumed they were new too. I should have looked more closely.... 😉

0 Kudos
Message 7 of 9
(2,146 Views)

@GerdW wrote:

Hi,

 

you all answered a 9 year old thread… 😄

 

(I guess this was triggered by a SPAM message, which is already removed by now.)


Facepalm moment!

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution
0 Kudos
Message 8 of 9
(2,116 Views)

@GerdW wrote:

Hi,

 

you all answered a 9 year old thread… 😄

 

(I guess this was triggered by a SPAM message, which is already removed by now.)


It's still in the wrong forum though! 😀

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 9 of 9
(2,099 Views)