|
I'm putting together a session-based data acquisition routine using MATLAB's Data Acquisition Tool box. The basic idea is to have a session started that continuously runs and only logs the data to a file. I have to run the session continuously as the experiments that I run for an unknown length of time and, hence, need to be terminated by the user. At the bottom of the post, there is a minimum working example of what I am trying to do. Not that I am using a National Instruments based DAQ and using MATLAB 2012a.
The problem that I run into is that the time stamps for the data acquisition points reset to 0 every 10 seconds. So, over the 20 seconds that the below code runs, the time data counter up from 0 to 10 and then resets to 0 and counts up to 10 again, instead of just counting up from 0 to 20. However, if I were to replace the line "session.IsContinous = true" to "session.DurationInSeconds = 20," so I setup the session to run for a finite amount of time, the time data goes from 0 to 20. So, there is some funny business going in with the IsContinuous flag set. I have tried setting "session.DurationInSeconds = 24*60*60," or to run for a day, which is much longer than the experiments are going to run. However, when you specify the session duration, it tries to allocate the memory necessary for an experiment of this length, which is more than my system can handle.
So, does anyone have any ideas on how to prevent the time stamps, used with the IsContinuous flag set, from resetting every 10 seconds? I have tried modifying pretty much every parameter in the session, and the time always rolls over every 10 seconds. Any help is much appreciated!!!!
Minimum working example:
% Setup session
session = daq.createSession('ni'); % Initialize session
session.IsContinuous = true; % Set the data acquisition to run continuously
session.addAnalogInputChannel('Dev',0,'Voltage'); % Add an input channel
% Setup logging of data
fid = fopen('log.bin','w');
hl = session.addlistener('DataAvailable',@(src,evnt)logData(src,evnt,fid));
% Start acquisition of data
session.startBackground;
% Normally, the user would end the session, but here we will just wait 20 seconds and end the session
pause(20);
session.stop;
delete(hl); % Delete listener
fclose(fid); % Close log file
%%%%%%%%%%%%
function logData(src,evnt,fid)
% Setup data array including the time stamps for each sample
data = [evnt.TimeStamps, evnt.Data];
fwrite(fid,data,'double');
|