Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Continuous acquisition without a callback function

Hi,

NI-DAQmx (C++), is it possible to continuously acquire samples without using a callback function? I see that in all Analog input C examples, continuous acquisition always comes with callbacks.

Thanks,
Peter


0 Kudos
Message 1 of 4
(3,229 Views)

Hi Peter,

You are correct that the shipping examples configure callbacks for registered DAQmx Events. BY no means are you required to use this architecture and calling DAQmxReadAnalogF64 (or similar) code in a loop would suffice.

Take a look at the following links for more info

Getting Started with NI-DAQmx: Main Page
https://www.ni.com/en/support/documentation/supplemental/06/getting-started-with-ni-daqmx--main-page...

Learn 10 Functions in NI-DAQmx and Handle 80 Percent of Your Data Acquisition Applications
https://www.ni.com/en/support/documentation/supplemental/06/learn-10-functions-in-ni-daqmx-and-handl...

Using NI-DAQmx in Text Based Programming Environments
https://www.ni.com/en/support/documentation/supplemental/21/using-ni-daqmx-in-text-based-programming...

 
PBear
NI RF
0 Kudos
Message 2 of 4
(3,208 Views)
I tried running it without a callback function, and I couldn't get it to work. Here's how I tried to do it:

*****************************************************
TaskHandle taskHandle;
DAQmxCreateTask("",&taskHandle);

//Create thermocouple channel
DAQmxCreateAIThrmcplChan(taskHandle, tcChannel,"",75,1500,DAQmx_Val_Kelvins, DAQmx_Val_K_Type_TC, DAQmx_Val_BuiltIn, 293, NULL);

//Sampling continuously at 6 samples per second
DAQmxCfgSampClkTiming(taskHandle,"", 6 ,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1);
DAQmxStartTask(taskHandle);

////***** Do other stuff that takes several seconds - after this there should be samples in the buffer

//Read buffer
DAQmxReadAnalogF64(taskHandle,1,0.5,DAQmx_Val_GroupByScanNumber,buffer,1,&numRead,NULL);

DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
*************************************************

I seem to do everything as the C function reference says, but the values read from the buffer are random numbers. Same setup works when using a callback function.




0 Kudos
Message 3 of 4
(3,197 Views)
Hi Peter,
 
Are you using a device with built in CJC? If not, you might get random numbers. Also, make sure that your selecting the correct physical channel as tcChannel sounds more like a global channel that is setup in MAX. Your timeout is also very short.
 
Are you getting any error messages? Try taking one of the shipping examples and rather than configure the parameters and remove the callbacks, just remove the callbacks and see if you can get data that makes sense.
PBear
NI RF
0 Kudos
Message 4 of 4
(3,181 Views)