How to collect last bits of data from background acquisition

1 view (last 30 days)
function trial
s = daq.createSession('ni');
addAnalogInputChannel(s,'Dev1', 'ai0', 'Voltage');
% addDigitalChannel(s,'Dev1','port0/line11','InputOnly');
s.IsContinuous = true;
s.Rate = 100;
s.NotifyWhenDataAvailableExceeds = 100;
% s.DurationInSeconds = 10;
lh = addlistener(s,'DataAvailable', @plotData);
tic;
startBackground(s);
pause(5.2);
stop(s);
toc;
end
function plotData(src,event)
fprintf('Length = %d\n',size(event.Data,1));
end
Im trying to run the above code in R2014a with the session interface. While I am able to get access to the first five data chunks, the last chunk with ~20 data points is not accessible. Any idea why?
I am basing this question on the online documentation for stop :
stop(s); stops the session and all associated hardware operations in progress. If your operation has acquired data and the DataAvailable event has not yet fired, the stop command will fire the event and deliver the data acquired up to that point.
  4 Comments
bas
bas on 21 Aug 2014
Edited: bas on 21 Aug 2014
I heard from matlab support:
"""
This is indeed a limitation in MATLAB. MATLAB gets the data in segments of size specified in 'NotifyWhenDataAvailableExceeds'. The 'DataAvailable' event will only be fired if it reaches the value of 'NotifyWhenDataAvailableExceeds'. If it is less than that it will be lost.
So when you call 'stop' in 5.2 seconds, only 500 bytes are captured and the rest of the data is lost.
Depending on your application, please consider any of the following as a workaround:
1. Allow the session to run for a bit longer than it is necessary, to make sure the data of interest is captured.
For example :
If you want the data which is captured at 5.2 seconds, you will have to call a 'stop' after 600 bytes of data is captured (i.e around 6-6.5 seconds later). Once 600 bytes the 'DataAvailable' event will again be fired.
Since you know that the rate of data acquisition, you can judge how much data will be received after a particular amount of time.
2. Consider decreasing the NotifyWhenDataAvailableExceeds property so the data point loss when the session is stopped is minimized. However, this property should not be set to less than 1/20 of the Rate of the session, to ensure all the callbacks are properly processed.
"""
Well that sucks!
Geoff Hayes
Geoff Hayes on 22 Aug 2014
Edited: Geoff Hayes on 22 Aug 2014
That is surprising/disappointing especially given the description on how the stop function works...

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!