07-30-2013 02:44 AM
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!
07-30-2013 03:03 AM
The board I use is PCI 6221. I'm afread the multithread cannot work...
08-14-2022 01:52 PM - edited 08-14-2022 01:53 PM
Since you posted in the LabVIEW forum, please explain how the question is related to LabVIEW. I don't quite see it.
08-14-2022 02:49 PM
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
08-14-2022 03:20 PM
@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.
08-15-2022 01:35 AM
08-15-2022 06:49 AM
@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.... 😉
08-15-2022 09:04 PM
@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!
08-16-2022 03:41 AM