I have an object that incorporates an event which is created in my program(specifically, a session based ni daq with a 'DataAvailable' event which fires every time a set number of samples is acquired.) This event will be fired at random times during the course of running my program that will do other stuff independent of recording. When fired, it will collect and save the data chunk in a file.
My issue is that everytime the Event is triggered, i need to increase a counter (i name it "chunk") in my original program. This is critical as a number of features in my program depend on my being able to measure the number of chunks accurately.
QUESTION: how can i propagate the fact that an event has been triggered into my main program?
For people who process (pseudo)code better:
setupStuff();
endLoop = false;
while ~endLoop
if ~recording
session = createDAQSessionObject(params);
chunkNum = 0;
session.addListener('DataAvailable',@(src,event)saveChunk(src,event,chunkNum));
session.startBackGround()
recording = true;
end
endLoop = doOtherStuff();
pause(0.1);
end
function saveChunk(src,event,numChunk)
filename = sprintf('chunk%d.mat',numChunk);
times = event.TimeStamps;
data = event.Data;
save(filename,'times','data');
% but now the next time around we need to get in numChunks+1 (but we never will because we have no way of knowing that the event was called...
end
Thanks
-bas