08-13-2009 01:57 PM
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!
08-14-2009 10:11 AM
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
08-14-2009 10:26 AM
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!
08-17-2009 03:04 PM
08-17-2009 03:18 PM
04-26-2010 08:31 AM
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:
Tasks(TaskCount).Timing.ConfigureSampleClock("", SampleRate, SampleClockActiveEdge.Rising, _ SampleQuantityMode.ContinuousSamples, numSamples * 1.1)
04-27-2010 09:27 AM
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
04-27-2010 10:16 AM
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?
04-28-2010 12:18 PM