logData too few inputs?
Ältere Kommentare anzeigen
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 Kommentare
Geoff Hayes
am 7 Mai 2015
Josh - is the logData function something that you have written or is it a MATLAB toolbox function? What is the signature for this function? (i.e. if you open the logData.m file, what are the inputs and outputs to this function).
Josh
am 11 Mai 2015
Antworten (0)
Kategorien
Mehr zu Data Acquisition Toolbox Supported Hardware finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!