12-22-2011 02:25 PM
Dear experienced users,
I am trying to continuously read the ai voltage from a DC LVDT. The voltage is from -5 v to 5v. The NI module I am using is NI 9239. The sampling rate is 1000 S/s. The samples per channel is 1000. The code goes like this:
DAQmxReadAnalogF64 (taskHandle, DAQmx_Val_Auto, 10.0,
DAQmx_Val_GroupByChannel, data, 1000, &read, 0);
The ai voltage is read into the buffer (array data), which is defined as:
static float64 data[1000];
Then the data is written to a dat file:
for (i=0;i<1000;i++)
fprintf (filehandle, "%f\n", data[i]);
When I check the dat file, I found a lot of zeros in the data array. In average about 200 -400 valid analogue voltage values (float64) are recorded, after that are zero values. I suspect only a portion of the buffer is used for the DAQmx read function, but not the whole buffer is used.
My question is: how can I know the exact array size of the buffer (data array) that is used? I do not want to use the if( data[i] != 0.0)
because the output is from -5.0 to 5.0 v.
Thanks,
Jimmy
12-27-2011 05:35 PM
I think what's happening is that you're reading from the buffer even though it's not full of data (because you're not reading fast enough to fill it). I think you might want to try reducing the size of the buffer from 1000 to something less, like 250 or 300. Do you want to ensure you get every data point?