Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Continuous sampling in NI-Daqmx Base

Hello,

I've hit a snag while using NI-DAQmx Base (I'm on Mac OS 10.4, compiling with gcc 4.0). The documentation says that calling DAQmxBaseReadAnalogF64 with numSampsPerChan (the second argument) set to -1 (DAQmx_Val_Auto) will cause whatever is in the buffer to be read. However, when I do this, only 2 samples are read (even though many more are clearly in there). This seems to happen irrespective of what sampling rate I've set the channel to.

I set the sampling clock like so:

status = DAQmxBaseCfgSampClkTiming(analog_input_task_handle, "OnboardClock",
(float64)analog_input_rate, DAQmx_Val_Rising,
DAQmx_Val_ContSamps, 0);

so there should be continuous sampling (analog_input_rate is typically a few kS/s). Changing the value of the final parameter makes no difference.

I'm reading the channel like so:

#define NIDAQ_BUFFER_SIZE 1000
float64 read_array[NIDAQ_BUFFER_SIZE];
status = DAQmxBaseReadAnalogF64(analog_input_task_handle, -1, (float64)NIDAQ_TIMEOUT,
DAQmx_Val_GroupByChannel, read_array,
(int32)NIDAQ_BUFFER_SIZE, &samples_per_channel, NULL);

samples_per_channel ends up always being two, and if the sampling rate is at all high, then the onboard buffer eventually overruns. If I set the second argument to something like 1000, it merrily reads the data out, but if I check too frequently, it blocks until it's gotten 1000 samples, and I check too infrequently, it gradually falls behind and blows up. Neither scenario is unacceptable behavior in my application.

I'm pulling my hair out. What gives?

Thanks,
Dave
0 Kudos
Message 1 of 4
(2,760 Views)
Hi Dave-

The "-1" setting for analog reads is not supported in DAQmx Base. DAQmx Base is meant to provide a subset of the DAQmx functionality and as such much of the documentation is the same. The line you're referencing that suggests this as a valid parameter was included unintentionally and has been removed from the documentation after its incorrect placement was pointed out by other customers.

Unfortunately this functionality is not available in DAQmx Base- we apologize for the confusion.

Thanks a lot-
Tom W
National Instruments
0 Kudos
Message 2 of 4
(2,751 Views)
Umm... I downloaded NI-Daqmx Base 1.5 one or two days ago and it was still in the documentation. I bought products under the assumption that your documentation was correct. I also developed a fair bit of code under that same assumption. I can't even begin to tell you what an annoyance this is. This isn't the first time I've been underwhelmed by NI, so I guess I'll think twice before buying again...

- Dave
0 Kudos
Message 3 of 4
(2,750 Views)
Hi Dave-

I apologize again for the confusion, but it will be possible for your application to work as designed with little modification.

There are a few options for the samples to read parameter. First, if you are performing a finite input operation you can simply specify this for the total number of samples to be acquired and a timeout that will exceed the expected operation time. This value can be computed easily by taking into account the hardware-timed sampling rate and the number of samples requested by the timing configuration.

If you are performing a continuous acquisition you can calculate an appropriate number of samples to read from the buffer with each read based on the hardware-timed acquisition rate and the loop iteration speed. In practice I generally set the loop iteration by placing a short delay to give a more reliable characterization of the frequency with which the read operation is called. The amount to read with each iteration is a matter of personal preference, but I generally choose a value in the 10-15% range of the sampling rate and then ensure that I do not call the read more than 10X per second.

Please take these suggestions into consideration as these are the methods that most people choose when programming applications that utilize their DAQ boards. I think you'll find that the board is reliable and that it works really well in either of these cases.

Thanks again-
Tom W
National Instruments
0 Kudos
Message 4 of 4
(2,728 Views)