How do I keep acquiring a signal with startBackrgound() for a specific amount of time after a condition is met?

1 Ansicht (letzte 30 Tage)
I'm acquiring a signal in the Background until a certain condition is met, specifically, until the voltage coming from one of the channels reaches a certain value. Here's the code I have so far:
s = daq.createSession('ni');
s.addDigitalChannel('Dev1', 'port0/line0', 'OutputOnly');
ai_channels_used = [1:8];
aI = s.addAnalogInputChannel('Dev1', ai_channels_used, 'Voltage');
for i=1:length(ai_channels_used)
aI(i).InputType = 'SingleEnded';
end
s.Rate = 4000;
fid = fopen('log.dat','w+');
lh = s.addlistener('DataAvailable',@(src,event)logDaqData(fid,event));
lh2 = s.addlistener('DataAvailable', @(src,event)stopF(src,event));
s.IsContinuous = true;
s.startBackground();
The logDaqData function simply logs the dta being recorded. The stoF function is the one I care about, that stops the acquisition once the voltage is reached, and it looks like this:
function stopF(src, event)
if (mode(event.Data(:,5)) > 1.25 && mode(event.Data(:,5)) < 7.5)
src.stop();
end
end
I would like to add something where once that condition is met, the signal is still acquired for an extra 1 sec, and then stops. I've tried adding
pause(1)
before the 'src.stop()' but it seems like that makes the code stop, and with it, the acquisition.
How can I solve this? Thanks!

Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by