Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmxReadAnalogF64 gives unexpected results with Ni 9239 - DAQmx

Solved!
Go to solution

Hi all,

I'm using a NI 9239 with a laser sensor, and I would like to acquire voltage readings from the sensor which measures height. It works great with Ni Max, but no in the C++/MFC app I'm developping. I get something which looks like amplidied noise:
1. the scale of the readings does not seem right (voltage readings I get range from -2E9 to 2E9)
2. changes in what the sensor is supposed to measure is not reflected in my measurements at all, there is nothing but noise (as if I was acquiring from the wrong channel - this I have double checked)
I woudl like to get the same output as in Ni Max, but can't figure out what wrong with my code (below). 

 

Thanks for your help,

 

Ben

 

 

// DAQmx Configure Code
DAQmxErrChk (DAQmxCreateTask("LaserReading",&taskHandle));
DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"cDAQ1Mod1/ai0","",DAQmx_Val_Diff,-10,10,DAQmx_Val_Volts,NULL));
DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,NULL,10000,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,5000));

// DAQmx Start Code
DAQmxErrChk (DAQmxStartTask(taskHandle));

// DAQmx Read Code
DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,NUM,-1,DAQmx_Val_GroupByChannel,data,5000,&read,NULL));

 

//TRACE sends the readings to the debug output

TRACE("Acquired %d points\n",read);
for(i=0; i<5000; i++)
{
TRACE("%d\n",data[i]);
}

DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);

0 Kudos
Message 1 of 2
(3,178 Views)
Solution
Accepted by topic author benACO

Found the answer to the problem, the problem was in the TRACE function which output the acquired data to the debugger. Changed %d to %f for floats in TRACE("%f\n",data[i]) - things are great now.

Thanks,

 

Ben

0 Kudos
Message 2 of 2
(3,169 Views)