How to generate a analog output signal each time a pushbutton is pressed from a GUI with the usage of an Ni-USB 6001 DAQ?

3 views (last 30 days)
I'm trying to generate a pulse signal to trigger a external stimulator for an experiment. I want to use a pushbutton to generate that signal wherever I want to output the trigger signal. I'm using a session-based code to acquire input signal and to output the trigger. I based my code with this example : https://www.mathworks.com/help/daq/examples/software-analog-triggered-data-capture.html. The problem I have is to configure the callback listener for the 'DataRequired' event. The listener in question is 'triglistener' and is define here :
trigListener = addlistener(s, 'DataRequired', @(src,event) triggerOutputUI(src, event, capture, hGui));
The callback function code is write down bellow. It consists of getting the value of two pushbuttons ('ManualButtonCortex' and 'ManualButtonMuscle') from the hGui figure. When a pushbutton is pressed, I want to output the Data with the call src.queueOutpuData on the analog output ai0 or ai1.
function triggerOutputUI(src, event, capture, hGui)
% Get capture toggle button value (1 or 0) from UI
ManualActiveRequestCortex = get(hGui.ManualButtonCortex, 'value');
ManualActiveRequestMuscle = get(hGui.ManualButtonMuscle, 'value');
if ManualActiveRequestCortex
set(hGui.StatusText, 'String', 'Cortex Trigger to AM Systems'); % To indicate the status in the GUI window
src.queueOutputData(outputData0);
elseif ManualActiveRequestMuscle
set(hGui.StatusText, 'String', 'Muscle Trigger to AM Systems'); % To indicate the status in the GUI window
src.queueOutputData(outputData1);
end
end
Should I create a new class for a events or is it possible to do it with the DataRequired Event?

Answers (0)

Categories

Find more on Data Acquisition Toolbox Supported Hardware in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!