logData too few inputs?

3 views (last 30 days)
Josh
Josh on 7 May 2015
Commented: Josh on 11 May 2015
Hey Everyone,
I am trying to write some code with data acquisition that will stop background data collection when a signal is greater than 1.0, as well as log the data I am collecting. I think I am just missing something simple. As the error I am getting says the logData function doesn't have enough input arguments. However, I believe I am passing it all that it needs in my function (src,event,fid1). Suppressing the logData line fixes all issues. Please see my code below, and let me know if I can provide more details.
Best, Josh
clear all
clc
% Work around for hardware clocking issue
daq.reset;
daq.HardwareInfo.getInstance('DisableReferenceClockSynchronization',true);
% Creates a data acquisition session
s = daq.createSession('ni');
% Add an input channel for the load cell
ch1 = addAnalogInputChannel(s,'Dev2',0,'Voltage');
% Preps a file for data write
fid1 = fopen('log.bin','w');
% Sets the listener call rate to default (10 Hz)
s.IsNotifyWhenDataAvailableExceedsAuto = true;
% Configure a new listener to process data until a stop condition is met
lh = addlistener(s,'DataAvailable',@stopWhenExceedOneNm);
% Configure the session to acquire continuously
s.IsContinuous = true;
% Start acquiring data in the background
s.startBackground()
The function being called:
function stopWhenExceedOneNm(src,event,fid1)
if any(event.Data > 1.0)
disp('Event listener: Detected Voltage exceeds 1, stopping acquisition')
% Continuous acquisition stopped explicitly
src.stop()
plot(event.TimeStamps,event.Data)
else
plot(event.TimeStamps,event.Data);
% Log data
logData(src,event,fid1);
disp('Event listener: Continuing to acquire')
end
end
  4 Comments
Josh
Josh on 11 May 2015
Thanks for the FAQ link, I think that would be the way to execute what I want to do. After some playing around though, I think adding multiple listeners may be the way to go for "simplicity". Thanks again.

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!