Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Session based data acquisition with "IsContinuous" set to true

Subject: Session based data acquisition with "IsContinuous" set to true

From: R Wat

Date: 15 Jun, 2012 15:44:07

Message: 1 of 4

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');

Subject: Session based data acquisition with "IsContinuous" set to true

From: R Wat

Date: 18 Jun, 2012 19:48:08

Message: 2 of 4

Amendment to my original post with respect to the following line:
> have tried modifying pretty much every parameter in the session, and the time always rolls over every 10 seconds.

I was wrong in saying that the time rolls over every 10 seconds. Rather, I now believe that it rolls over every 100 listener calls to "loadData."

Again, any help would be greatly appreciated!

Subject: Session based data acquisition with "IsContinuous" set to true

From: R Wat

Date: 19 Jun, 2012 15:56:09

Message: 3 of 4

So, after calling Mathworks, I found out that this is a reported bug in the toolbox. See http://www.mathworks.com/support/bugreports/795145 for a solution to the issue. Basically, when you have mixed inputs (analog and digital inputs), there is an issue with the time stamp property.

Subject: Session based data acquisition with "IsContinuous" set to true

From: Anne

Date: 5 Jul, 2012 08:34:09

Message: 4 of 4

"R Wat" wrote in message <jrq7eo$bfs$1@newscl01ah.mathworks.com>...
> So, after calling Mathworks, I found out that this is a reported bug in the toolbox. See http://www.mathworks.com/support/bugreports/795145 for a solution to the issue. Basically, when you have mixed inputs (analog and digital inputs), there is an issue with the time stamp property.

Hello,

I installed the bug fix, but still have trouble with the time stamp property (it restarts from zero when should not). Did you manage to get it working properly?

Thanks

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us