11-13-2013 01:14 PM
I have two analog inputs using USB 6221 and I want to measure the voltage of each one. I'm using DAQmx-read vi and I select Analog Input, 1 Sample, Multiple Channels, but I don't know how to connect multiple channels to the Physical Channel input.
Solved! Go to Solution.
11-13-2013 01:30 PM
Hello Bernadette,
For reference- I'd recommend posting DAQmx-specific questions here:
NI Forums: Multifunction DAQ
http://forums.ni.com/t5/Multifunction-DAQ/bd-p/250
There are a number of ways to add multiple channels to a task- a quick ni.com search for "select multiple channels DAQmx" gives me this as the top hit:
KnowledgeBase 2X8D7F5Z: How Do I Select More Than One NI-DAQmx Channel in LabVIEW?
http://digital.ni.com/public.nsf/allkb/A3A05920BF915F1486256D210069BE49
Hope that helps!
11-13-2013 02:07 PM
I just use Initialize Task multiple times to add a channel. My code usually has this in a FOR loop so I can iterate on an array of inputs.
11-13-2013 02:09 PM
Or just build a task with more than one input and read "single sample multiple channels", pick the inputs out of the array.
Dev1/ai0:3 will make an array of AI0, AI1, AI2, and AI3 inputs.
12-10-2013 05:46 AM
How to read "single sample multiple channels"?
And Dev1/ai0:3 means ai0 to 3. What if I want to select only two of them, for i.e: Dev1/ai0 and Dev1/ai6.
In my application I need to read from two AI channels successively given an AO, which is triggered by the AI task. Anyone can give a ref?
12-10-2013 06:23 AM
Just fill it in like this:
Dev1/ai0, Dev1/ai6
The syntax can be found here
12-10-2013 06:58 AM
Thanks a lot Koen.
Maybe it is primitive but what I want to do is to read from two AI while generating 1 AO. Here is my code:
....
DAQmxErrChk (DAQmxCreateTask("",&AItaskHandle));
DAQmxErrChk (DAQmxCreateAIVoltageChan(AItaskHandle,"Dev1/ai0,Dev1/ai6","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(AItaskHandle,"",50000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));
DAQmxErrChk (GetTerminalNameWithDevPrefix(AItaskHandle,"ai/StartTrigger",trigName));
DAQmxErrChk (DAQmxCreateTask("",&AOtaskHandle));
DAQmxErrChk (DAQmxCreateAOVoltageChan(AOtaskHandle,"Dev1/ao0","",-10.0,10.0,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(AOtaskHandle,"",50000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));
DAQmxErrChk (DAQmxCfgDigEdgeStartTrig(AOtaskHandle,trigName,DAQmx_Val_Rising));
DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(AItaskHandle,DAQmx_Val_Acquired_Into_Buffer,1000,0,EveryNCallback,NULL));
DAQmxErrChk (DAQmxRegisterDoneEvent(AItaskHandle,0,DoneCallback,NULL));
// Generate the waveform
GenSineWave(1000,1.0,1.0/1000,&phase,AOdata);
DAQmxErrChk (DAQmxWriteAnalogF64(AOtaskHandle, 1000, FALSE, 10.0, DAQmx_Val_GroupByChannel, AOdata, NULL, NULL));
DAQmxErrChk (DAQmxStartTask(AOtaskHandle));
DAQmxErrChk (DAQmxStartTask(AItaskHandle));
And when the read data is called inside EveryNCallback by:
DAQmxErrChk (DAQmxReadAnalogF64(AItaskHandle,1000,10.0,DAQmx_Val_GroupByChannel,AIdata[curBuffer],1000,&readAI,NULL));
I see nothing but zeros for the AIdata.
Do I have a synchronization problem?
Bests,
All comments are appreciated.
12-10-2013 07:03 AM
Could you add your vi? Makes it a lot easier
12-10-2013 07:07 AM
Hi Koen,
I am not using Labview. I am writing the code in C. As I cannot create a VI in C.
12-10-2013 07:18 AM
Hello ozandogan,
I'm sorry then I'm not able to help you.
Koen