Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Samples No Longer Available

I have an application that reads 30-40 temperatures and voltages from four different devices.  2 are PCI-6032s and 2 are compact DAQ chassis.  There are 4 AI tasks, one for each device.  I want to read 10 samples from each channel every second.  That should be about 400 samples per read.  My rate has been anywhere from 1000-10000.  Initially, I was only using about 10 channels.  After adding the rest, I am getting a problem with the continuous sampling and the call back function.  The error is as follows:

 

********************************************************************

 

 21:17:07    BeginRead
NationalInstruments.DAQmx.DaqException: Measurements: Attempted to read samples that are no longer available. The requested sample was previously available, but
has since been overwritten.
 
Increasing the buffer size, reading the data more frequently, or specifying a fixed number of samples to read instead of reading all available samples might correct the problem.
 
Property: NationalInstruments.DAQmx.DaqStream.ReadRelativeTo Corresponding Value: NationalInstruments.DAQmx.ReadRelativeTo.CurrentReadPosition Property: NationalInstruments.DAQmx.DaqStream.ReadOffset
Corresponding Value: 0
 
Task Name: Task1task
 
Status Code: -200279
   at NationalInstruments.DAQmx.Internal.AnalogMultiChannelMultiSampleReadAsyncResult.End()
   at NationalInstruments.DAQmx.Internal.AnalogMultiChannelReaderImpl.EndReadMultiSample(IAsyncResult IAsyncResult)
   at NationalInstruments.DAQmx.AnalogMultiChannelReader.EndReadMultiSample(IAsycResult asyncResult)
   at PCDAQS.modCallbacks.AnalogInCallback(IAsyncResult ar) in C:\PCDAQS Source\modCallbacks.vb:line 40
 
 1:17:07    EndRead
NationalInstruments.DAQmx.DaqException: Measurements: Attempted to read samples that are no longer available. The requested sample was previously available, but  has since been overwritten.
 
Increasing the buffer size, reading the data more frequently, or specifying a fixed number of samples to read instead of reading all available samples might correct the problem.
 
Property: NationalInstruments.DAQmx.DaqStream.ReadRelativeTo Corresponding Value: NationalInstruments.DAQmx.ReadRelativeTo.CurrentReadPosition Property: NationalInstruments.DAQmx.DaqStream.ReadOffset Corresponding Value: 0
 
Task Name: Task1task
 
Status Code: -200279
   at NationalInstruments.DAQmx.Internal.AnalogMultiChannelMultiSampleReadAsyncResult.End()
   at NationalInstruments.DAQmx.Internal.AnalogMultiChannelReaderImpl.EndReadMuliSample(IAsyncResult asyncResult)
   at NationalInstruments.DAQmx.AnalogMultiChannelReader.EndReadMultiSample(IAsycResult asyncResult)
   at PCDAQS.modCallbacks.AnalogInCallback(IAsyncResult ar) in C:\PCDAQS Source\modCallbacks.vb:line 22

 

******************************************************************** 

 

Once this error happens, the application is unable to continue reading data.  I have posted the call back function below.  Is there any way I can avoid this error altogether or if not, recover from it?

 

    Public Sub AnalogInCallback(ByVal ar As IAsyncResult)
        Dim TaskNumber As Byte
        TaskNumber = CType(ar.AsyncState, Integer) 'cast the user object passed when registering the callback to an integer
        Try
            If taskRunning = True Then
                Select Case TaskNumber
                    Case Is = 0
                        Task1Data = reader(TaskNumber).EndReadMultiSample(ar)
                    Case Is = 1
                        Task2Data = reader(TaskNumber).EndReadMultiSample(ar)
                    Case Is = 2
                        Task3Data = reader(TaskNumber).EndReadMultiSample(ar)
                    Case Is = 3
                        Task4Data = reader(TaskNumber).EndReadMultiSample(ar)
                End Select
            End If
        Catch ex As Exception
            ' Error Handling

       End Try
        Try
            reader(TaskNumber).BeginReadMultiSample(numSamples, AsyncCallback, TaskNumber)
        Catch ex As DaqException
            Try
                reader(TaskNumber).BeginReadMultiSample(numSamples, AsyncCallback, TaskNumber)
            Catch ex1 As Exception
                MessageBox.Show("Unable to start reading.")
            End Try
        End Try
    End Sub

 

Thanks!

Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 1 of 9
(6,648 Views)

I understand that you are trying to read 40 temperature channels 10 times per second and are receiving a buffer overflow error.  This error happens when you do not read off the buffer of the card fast enough and the card is sampling at such a rate that previously read smaples get overwritten.  This first question I would have is where is your rate of 1000-10,000 come from.  I would imagine all channels would be sampling at a rate of 10 Hz to correspond to your desired sampling rate of 10 samples per second.

 

If you set your rate to 10 Hz you should almost never run into this error if you are running any sort of modern computer as the error happens when the computer does not run fast enough to read data off the cards buffer fast enough.  Check out the following knowledgebase article found on ni.com about this error.

 

http://digital.ni.com/public.nsf/allkb/6C05A002FAE4F9F68625734C0059B4EF?OpenDocument

 

 

Doug Farrell
Solutions Marketing - Automotive
National Instruments

National Instruments Automotive Solutions
0 Kudos
Message 2 of 9
(6,638 Views)

I have been sampling faster because I never thought of the benefit of reading samples at some rate that aquires them over the entire second.  That would be a more realistic number (as opposed to getting them as fast as possible).  I will try this out and report back. 

 

Quick question, however...

 

Is sample rate the rate of samples per channel, or the rate to aquire all samples for this tast?

 

For instance: 10 channels, 10 samples/S/ch  That's 100 samples per second.  Would my rate be 10 or 100?

 

Thanks!

 

 

Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 3 of 9
(6,635 Views)
The rate specified is the samples per channel.  So in your example you would specify 10 as the rate.  Let me know how your testing turns out.
Doug Farrell
Solutions Marketing - Automotive
National Instruments

National Instruments Automotive Solutions
0 Kudos
Message 4 of 9
(6,610 Views)
I slowed it down to 410 because I didn't know if it was samples per task or samples per channel.  I'll reduce it to 10.  Thanks!
Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 5 of 9
(6,608 Views)

I have a computer that is having this problem frequently now.  I am reading 100 samples over 0.1 seconds and averaging their values.  This means I need a sample rate of 1000 S/s.  The method of reading is continuous.

 

My options are to:

  1. Increase the number of samples per channel with the DAQmx Timing VI. (Increase buffer size)
  2. Increase the number of samples per channel to read with the DAQmx Read VI. (Reads faster)
  3. Decrease the samples per channel rate with the DAQmx Timing VI. (Write slower)
Should I increase the buffer size as shown below by multiplying the number of samples to read by 1.1 (110) and then only asking for 100 samples?  Would a sample rate of 900 cause problems, because that is what it was set at?

 

 

Tasks(TaskCount).Timing.ConfigureSampleClock("", SampleRate, SampleClockActiveEdge.Rising, _ SampleQuantityMode.ContinuousSamples, numSamples * 1.1)

 

 

 

 

Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 6 of 9
(5,922 Views)

If you are only reading 100 samples and stopping that should be fine.  However if you are doing this continuously I would increase it a bit.  A windows maching can run a loop at best around 10-20 ms so that is how often your Read Fetches are happening out of the buffer.  So I would plan on worst case, lets say 50 ms because you're running iTunes and Tetris in the background and then set it to 1.1 x 0.5 seconds x 1000 Hz Sample Rate and use 550 samples.

 

Were you manually setting the buffer size before?  Because the DAQmx driver should've handled this for you to allocate a buffer of 10,000 samples at 1000 S/s according to the following document:

 

http://digital.ni.com/public.nsf/allkb/E1E67695E76BA75B86256DB1004E9B07?OpenDocument

 

 

 

Doug Farrell
Solutions Marketing - Automotive
National Instruments

National Instruments Automotive Solutions
0 Kudos
Message 7 of 9
(5,889 Views)

I have to specify some number. 

 

You're saying to set the buffer to 550 in order to read 100 S and 1000 S/s continuously?

Programming Data Acquisition and Control in Measurement Studio and Labwindows/CVI
0 Kudos
Message 8 of 9
(5,884 Views)
Yes, I was saying to set it to 550 at 1000 S/s.  Alernatively you could experiment with some values to find the smallest number that does not give you this error.
Doug Farrell
Solutions Marketing - Automotive
National Instruments

National Instruments Automotive Solutions
0 Kudos
Message 9 of 9
(5,860 Views)