From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How to acquire multiple channel data with NIDAQmxBase & USB6009

Hello,

I have written an application in C++ for the USB 6009 unit. I have successfully been able to simultaneously acquire data from the "ai0" and "ai1" channels. When I go for "ai2" and "ai3" the data starts to look confused...not sure how the DAQmx_Val_GroupByChannel works or whether I should use GroupByScanNumber.

Here's my code (snippets from my prog):

char Dev1_joint1_channels[] = "Dev1/ai0:1";
char Dev1_joint2_channels[] = "Dev1/ai2:3";//the only reason I split this is to test with and without
//buffersize is 500
uInt64 samplesPerChan = bufferSize/4;
// Data read parameters
float64 data[bufferSize];
int32 pointsToRead = bufferSize;

/---------Initialize the task--------------------/
DAQmxErrChk (DAQmxBaseCreateTask("",&taskHandle));

DAQmxErrChk (DAQmxBaseCreateAIVoltageChan(taskHandle,Dev1_joint1_channels,"",DAQmx_Val_Diff,min,max,DAQmx_Val_Volts,NULL));

DAQmxErrChk (DAQmxBaseCreateAIVoltageChan(taskHandle3,Dev1_joint2_channels,"",DAQmx_Val_Diff,min,max,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxBaseStartTask(taskHandle));
/------------------------------------------------/

WHILE LOOP
{
/---------Acquire data--------------------------/
DAQmxErrChk (DAQmxBaseReadAnalogF64(taskHandle,pointsToRead,timeout,DAQmx_Val_GroupByChannel,data,samplesPerChan,&pointsRead,NULL));
/-----------------------------------------------/

/---------Assign to variables after averaging---/
joint1_chanA = arrayAverage(data,0,pointsToRead/4);
joint1_chanB = arrayAverage(data,pointsToRead/4,pointsToRead/4);
joint2_chanA = arrayAverage(data,pointsToRead/2,pointsToRead/4);
joint2_chanB = arrayAverage(data,pointsToRead*3/4,pointsToRead/4);
/-----------------------------------------------/
}//END WHILE LOOP

This works perfectly for just 2 channels, without even using the timer. I tried to stick the timer in, but the acquisition would not even go at that point. With 2 channels, I simply average the first half of data and assign it to the appropriate variable and then do the same for the second half. This works very well for just 2 channels, it's when i get into 4 channels that the data either doesn't show up, or is very confusing.

Help is appreciated!
Thank you!
Nathan
nbluvol@imaging.robarts.ca
0 Kudos
Message 1 of 3
(3,194 Views)
I've got a couple things that might help out.
First, on the DAQmxRead function, you give it 'pointsToRead' and it looks like you are expecting that to give you 500 points total (you set pointsToRead = buffersize = 500). What that function will do is read 500 points from each channel in your channel list. So if you have 4 channels, that will read 2000 points. So your data array needs to be pointsToRead * Number of Channels.
Secondly, about the GroupByChannel or GroupByScanNumber:
GroupByChannel will do what you were anticipating. Best described with an example. Channels 0, 1 and 2. Acquiring 3 scans (per channel). Data array will be like this [ch0, ch0, ch0, ch1, ch1, ch1, ch2, ch2, ch2].
GroubByScanNumber will interleave the data points like this [ch0, ch1, ch2, ch0, ch1, ch2, ch0, ch1, ch2].
I hope I was able to explain this effectively. If not, repost your question(s).
-Alan A.
Message 2 of 3
(3,176 Views)
Excellent! Thank you! That explains it very well, I think i got it working now.

Thanks again,
Nathan
0 Kudos
Message 3 of 3
(3,170 Views)