Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use DAQmx Read to measure multiple analog channels

Solved!
Go to solution

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.

Message 1 of 16
(52,010 Views)
Solution
Accepted by topic author Bernadette

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!

Tom L.
Message 2 of 16
(52,005 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 16
(51,997 Views)

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.

0 Kudos
Message 4 of 16
(51,995 Views)

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?

0 Kudos
Message 5 of 16
(51,888 Views)

Just fill it in like this:

Dev1/ai0, Dev1/ai6

 

The syntax can be found here

---

UnCertified LabVIEW Student
Mistakes are for learning, that's why suggestions are always welcome!
Message 6 of 16
(51,871 Views)

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.

 

0 Kudos
Message 7 of 16
(51,860 Views)

Could you add your vi? Makes it a lot easier

---

UnCertified LabVIEW Student
Mistakes are for learning, that's why suggestions are always welcome!
Message 8 of 16
(51,857 Views)

Hi Koen,

I am not using Labview. I am writing the code in C. As I cannot create a VI in C.

0 Kudos
Message 9 of 16
(51,854 Views)

Hello ozandogan,

 

I'm sorry then I'm not able to help you.

 

Koen

---

UnCertified LabVIEW Student
Mistakes are for learning, that's why suggestions are always welcome!
0 Kudos
Message 10 of 16
(51,842 Views)