Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

NI Daq BeginReadMultiSample continuous sampling gets zero data when samples -1

Solved!
Go to solution

My need: Continuously sample two analog channels (NI 9209) at 100 Hz for an indeterminate amount of time. Essentially start sampling and stop at some later time which may be 10 seconds or 10 days. I have to get all samples and cannot drop any.

 

What I tried: I created a simple test program using this project as a template:

NI-DAQ\Examples\DotNET4.5.1\Analog In\Measure Voltage\ContAcqVoltageSamples_IntClk_ToFile\CS

 

This code works when I set the first parameter of BeginReadMultiSample to 10. I see data from EndReadMultiSample.

But if I change the first parameter of BeginReadMultiSample to -1 I get no data returned from the call to EndReadMultiSample

 

//Read the available data from the channels
data = analogInReader.EndReadMultiSample(ar);

 

I searched all the sample code and found no examples setting BeginReadMultiSample samples to -1, even though the documentation suggest that this what I do to get continous sampling.

 

What am I missing?

How should I modify the example so that I get continuous data sampling with no samples dropped?

0 Kudos
Message 1 of 3
(3,183 Views)
Solution
Accepted by topic author cmz

Hi cmz, 

 

The number of samples argument for the "BeginReadMultiSample" function is going to determine how many samples is taken from the FIFO buffer of your 9209 to your Host PC everytime you call the read function. No samples is dropped, this just means that instead of taking all the samples available in the buffer, it will take 10 at a time. The example you are using is already set for continuous sampling.

This is done when you set the sample clock:

"myTask.Timing.ConfigureSampleClock("", Convert.ToDouble(rateNumeric.Value),
SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, 1000);" 

 

Therefore, when you set the samples argument to -1 when you are in continuous sampling mode, the read will retrieve all samples that are available in your buffer instead of only taking the number you enter in the UI at a time.

However, your acquisition is still continuous and will not drop any samples even though that number is not set to -1 so you are good to go!

 

If you do want to set that number to -1, here is how you would do it: 

int takeAllSamples = -1;
analogInReader.BeginReadMultiSample(takeAllSamples, analogCallback, myTask);

 

The reason you cannot change the samples/channel in the UI to -1 is because other functions are dependent on that number and they cannot take a negative argument.

 

I hope this helps!

T. Le
Vision Product Support Engineer
National Instruments
0 Kudos
Message 2 of 3
(3,148 Views)

Hi,

 

I am still getting 0 while using -1 as takeAllSamples.

 

I have similar purpose as explained by the author of this thread i.e. Start sampling..do something..after sometime stop sampling. The value of sometime is unknown to me. Here is my code snippet. Please tell me what I am doing wrong.

 

Even if I use ..SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, 1000), the result is empty buffer.

 

Thanks and regards

Ricky

StartSampling()
{
     mGlobalTask.Timing.SampleTimingType = SampleTimingType.SampleClock;
     mGlobalTask.Timing.ConfigureSampleClock(string.Empty, samplesPerSecondPerChannel, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples);
     mGlobalTask.Stream.Timeout = -1;
     mGlobalAnalogChannelReader = new AnalogMultiChannelReader(mGlobalTask.Stream);
     mAsyncResult = mGlobalAnalogChannelReader.BeginReadMultiSample(-1, null, mGlobalTask);
}

StopSampling(out double[,] aReadBuffer)
{
aReadBuffer = mGlobalAnalogChannelReader.EndReadMultiSample(mAsyncResult);
}

Earlier I used callback. It worked well but didn't solve the purpose because a callback is called when sampling is complete and as I mentioned, I don't know when it is going to finish. Sometime after StartSampling, I call StopSampling and expect aReadBuffer full of data acquired

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