Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with DAQmxReadAnalogF64

I have to acquire, every 5 seconds, two temperatures (indoor and
outdoor); the sensors are connected to ai0 and ai1.

I created one AI task then I added to it two AI channel.

Finally DAQmxReadAnalogF64 should read from these channel
the acquired samples.

The error I got is the following:

DAQmx Error: A synchronization object was not acquired within the time
limit. The operation could not be completed as specified.
Task Name: TaskAI
Status Code: -50550

Here it is the piece of code used to read samples:

/* start code */

while( !_kbhit() ) {

Sleep(5000); /* every 5 seconds */

DAQmxErrChk(DAQmxReadAnalogF64(
taskHandle,
DAQmx_Val_Auto,
10,
DAQmx_Val_GroupByScanNumber,
array,
1, /* read 1 sample for channel */ &totals,
NULL));


/**** PRINT RESULTS ****/

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

vet[0] * 9.91, /* 9.91 is a scale factor */

vet[1]);

}

/* end code */

Thanks in advance
0 Kudos
Message 1 of 4
(4,432 Views)

Hi,

A great way to program is to take one of the shipping examples and modify it to fit your specific application. I checked and found some examples specifically for acquiring thermocouple data. They are located in C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Analog In\Measure Temperature. I recommend running one of these to make sure that you are acquiring accurate data and then modifying it to your specific timing.

Regards,
Hal L.

0 Kudos
Message 2 of 4
(4,424 Views)
Hal L ha scritto:

> A great way to program is to take one of the shipping examples...

I already looked at it but I didn't understand how to use ReadAnalogF64
for the following reasons:

1. all the examples are regarding to one AI (I have two AIs)
2. all the examples only the total number of samples acquired; no
example about how to "extract" values from the array.

So all it's still unclear to me.

Thanks again.
0 Kudos
Message 3 of 4
(4,419 Views)
Hello Rossi,

The best reference for programming DAQmx applications in C is the 'DAQmx C Reference Help' located under Start > All Programs > National Instruments > NI-DAQ.  In order to create a DAQmx application to read from multiple analog input channels, you will first need to specify the channels in the DAQmxCreateAIVoltageChan function.  If you find this function in the reference help, it explains for the parameter 'physicalChannel', you can specify an individual or range of physical channels to acquire from.  There is a link to another page title 'Physical Channel Syntax' that explains how to enter the channel string into this function.  To sample from analog input channels 0 through 1 on Dev1, you would enter "Dev1/ai0:1".  With a multiple channel task created, you read from that task using the DAQmxReadAnalogF64 function.  Find this function in the DAQmx C Reference Help, and it explains that the readArray output of this function produces an array of data for all the channels.  Whether the data in that array is grouped by channel or interleaved is specified by the fillMode parameter of the DAQmxReadAnalogF64 function.  This should help you get started with acquiring data from multiple channels using the DAQmx functions.

As far as extracting data from an array, you can extract an individual number from an array by specifying it by its element, or order in the array.  Doing a quick search, I found many helpful tutorials on working with arrays in C.  Here's one I found especially helpful.

I hope this helps.

Regards,
Travis G.
Applications Engineering
National Instruments
www.ni.com/support
0 Kudos
Message 4 of 4
(4,407 Views)