Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Re: Issue with DAQmxReadAnalogF64

Please, would you so kind to explain me how I can do to read two AIs
from a same task? I didn't found no example in help and I still get errors.

Here it is my code:

/**** BEGIN CODE *****/

float64 data[2];

/* Indoor temperature */
DAQmxErrChk (DAQmxCreateAIVoltageChan(
taskHandle,
"Dev1/ai0",
"",
DAQmx_Val_Diff,
0,
5,
DAQmx_Val_Volts,
""));

/* Outdoor temperature */
DAQmxErrChk (DAQmxCreateAIVoltageChan(
taskHandle,
"Dev1/ai1",
"",
DAQmx_Val_Diff,
0,
5,
DAQmx_Val_Volts,
""));

DAQmxErrChk (DAQmxCfgSampClkTiming(
taskHandle,
"OnboardClock",
5000.0, /* because fs must be <= 10000/2 */
DAQmx_Val_Rising,
DAQmx_Val_ContSamps ,
1));

DAQmxErrChk( DAQmxStartTask(taskHandle));


while( !_kbhit() ) {

Sleep(1000); (/* refresh every 1 second */

DAQmxErrChk(DAQmxReadAnalogF64(
taskHandle,
-1,
10,
DAQmx_Val_GroupByScanNumber,
data, 1, &total,
NULL));

printf("[Indoor: %3.0f C] [Outdoor: %3.0f C]\r",

vet[0]*9.91, /* 9.91 is a scale */
vet[1]);
}
/**** END CODE *****/


Here the output:

[***** BEGIN OUTPUT *****]

Task Name: Task_AI

Status Code: -200229
[Temp.int.:
-917265946671739660000000000000000000000000000000000000000000000 C]
DAQmx Error: Buffer is too small to fit read
data.0000000000000000000000000 C]
Buffer Length: 1
Required Buffer Size in Samples: 8

[***** END OUTPUT *****]
0 Kudos
Message 1 of 2
(3,531 Views)
Hi rossi,

I hope you're doing well.  There are a couple of things I noticed off the bat: 1.)  You have created two seperate tasks for teach AI channel by using DAQmxCreateAIVoltageChan.  You can only have one analog input task running at any given time, so the way around this is by by using something like "Dev1/ai0:1" in your physical channel string.  By using a colon, you span all channels between channels 0 and 1.  2.)  When you are doing a continuous mode acquisition as you have specified in the DAQmxCfgSampClkTiming function, your sampPerChanToAcquire parameter has a minimum number.  This parameter sets your buffer size, and by setting this value to 1, it is causing the error message that you are receiving.  Try implementing these changes and see if that helps you along with your application.  If you are still having trouble, please let us know and we will try our best to help.  Have a good day!

Thaison V
Applications Engineer
National Instruments
0 Kudos
Message 2 of 2
(3,522 Views)