Repeat queued output data using startBackground

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 个)

类别

帮助中心File Exchange 中查找有关 Data Acquisition Toolbox Supported Hardware 的更多信息

产品

版本

R2019b

提问:

2022-3-1

Community Treasure Hunt

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

Start Hunting!

Translated by