Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

How to read two an.inputs at the same time

How I could read (at the same time)
two voltages (slow varying) from
two analog inputs?

I'm using ANSI C (with NI-DAQmx
API C functions).

Thanks in advance
0 Kudos
Message 1 of 8
(4,873 Views)
Frank ha scritto:
> How I could read (at the same time)
> two voltages (slow varying) from
> two analog inputs?

I'm using DAQmxReadAnalogF64 but
I don't know how use the array filled
with the data acquired from two input
0 Kudos
Message 2 of 8
(4,869 Views)
Create an Analog Input task and add two channels.
Start the task.
Pass the following parameters to DAQmxReadAnalogF64:
taskHandle
samplesPerChannel = 1
timeout = 10.0 (or your preferred value)
fillMode = DAQmx_Val_GroupByChannel (does not matter here)
readArray = buffer (float64 array of at least two elements)
arraySizeInSamples = 2
samplesPerChannelRead = &read (int32 variable)
reserved = 0

Upon successful return from this function call, the buffer will contain two values, one for each channel, in the same order you created the channels in the task.

Ludek
NI
0 Kudos
Message 3 of 8
(4,859 Views)
lpekarek ha scritto:
> Create an Analog Input task and add two channels.

Using DAQmxAddGlobalChansToTask
or using, i.e., "Dev1/ai0:1" as pysical channel?

Your examples is based upon a SW timed:
sleep() and while(!_kbhit) . Is it?

Thanks again
0 Kudos
Message 4 of 8
(4,857 Views)
Correct, you can add channels to your task by either adding existing global channels or by creating AI channels. Both ways work.

You can time your acquisition in any way you desire. Yes, Sleep() and _kbhit() are sufficient on a Windows platform.

Feel free to modify the examples to fit your needs.

Ludek
NI
0 Kudos
Message 5 of 8
(4,851 Views)
lpekarek ha scritto:

> Correct, you can add channels to your task by either adding existing global channels or by creating AI channels.

Tough, if I understood well, if I choose to use physical channel
"dev1/ai0:1" I must use same input configuration (vmin,vmax RSE or
differential) for both inputs, while if I add global channel to the task
I could config input in a different manner (i.e. RSE for dev1/ai0
and differential for dev1/ai1...). Is it?
Thanks again, you help was greatly appreciated.
0 Kudos
Message 6 of 8
(4,853 Views)

Actually either method will work (using physical channels or Global channels) for setting those properties.  In one case you just add the global channel in the other case you would use some sort of for loop to set each of the channels in the list to whatever input configuration you wanted to setup.

StuartG

0 Kudos
Message 7 of 8
(4,843 Views)
Frank:

"Global channel" means a channel that's configured in MAX. Global channels are nice if you want to use a channel in multiple programs, or if you want to use an interactive editor (the DAQ Assistant) to design your channel, rather than writing all the code to do it. They're also useful if you're moving from Traditional DAQ to DAQmx, as DAQmx Global Channels are very similar to Traditional DAQ Virtual Channels. You use the DAQmxAddGlobalChansToTask function to add a global channel that you've configured in MAX to a task.

Alternatively, you can create channels completely in your code. In this case, you would use one of the many measurement-specific channel creation functions, like DAQmxCreateAIVoltageChan, and supply all the channel parameters programmatically.

Anything you can setup via a Global Channel, you can also setup programmatically. Choosing between the two is really a matter of deciding which is more convenient for you. You're right that if I make one call to the DAQmxCreateAIVoltageChan function and pass a channel string containing multiple channels (like "Dev1/ai0:7"), then other parameters I pass in that function (like terminal configuration) must apply to all the channels. However, you can call DAQmxCreateAIVoltageChan multiple times (once for "Dev1/ai0", again for "Dev1/ai1", etc.) if you want to specify different values.

Finally, I should mention that if you're new to DAQmx and are interested in using the DAQ Assistant, you should look at creating tasks in the Assistant, rather than global channels. New DAQmx users tend to prefer creating tasks directly, as this keeps all your settings together.

-- Chris
0 Kudos
Message 8 of 8
(4,838 Views)