Repeat queued output data using startBackground

조회 수: 6 (최근 30일)
wbriand
wbriand 2022년 3월 1일
I wrote a script to perform signal acquisition of 4 strain sensors using DAQ toolbox. I use session based code to match the rest of my project.
The objective is to plot analog signals when they exceed a threshold. To carry out voltage measurement, I need to assign a constant 1 value to 4 digital channels (one by sensor) for the duration of the acquisition. However, the acquisition duration is long and unknow (it will end by an external trigger). Thus, I would like to find a way to assign a constant output value to digital channels OR perform measurements by small step in a while loop using the same queued data as done here: https://fr.mathworks.com/help/daq/generate-continuous-and-background-signals-using-ni-devices.html#d123e18127
Here is my script
% Session parameters
session=daq.createSession ('ni');
session.Rate=2e6;
duration=5;
% Add analog input
addAnalogInputChannel(session,'Dev3',0,'Voltage');
addAnalogInputChannel(session,'Dev3',1,'Voltage');
addAnalogInputChannel(session,'Dev3',2,'Voltage');
addAnalogInputChannel(session,'Dev3',3,'Voltage');
% Add digital output
addDigitalChannel(session,'Dev3','port0/line0','OutputOnly');
addDigitalChannel(session,'Dev3','port0/line1','OutputOnly');
addDigitalChannel(session,'Dev3','port0/line2','OutputOnly');
addDigitalChannel(session,'Dev3','port0/line3','OutputOnly');
% Add listener for startBackground function
addlistener(session,'DataAvailable',@(src,event) callback(src,event)) ;
session.IsContinuous = true ;
queueOutputData(session,ones(round(session.Rate*duration),4)) ; % add constant 1 output to digital channels
startBackground(session) ;
% MISSING BLOCK
function callback(src,event) % plot data is signals exceed threshold
if any(event.Data>1e-2) % hardcoded threshold
plot(event.TimeStamps, event.Data)
end
end

답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Acquisition Toolbox Supported Hardware에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by