I'm trying to make a GUI with which I control signals that i want to send and receive to/from my NI DAQ device.
For now I have a GUI with an axes, a start and a stop button.
There should be a contineous measurement of the analog input channels for as long as i dont quit the operation.
When I press the start button I want a sine wave of 10seconds sent to the analog output.
When I press the stop button I want this signal to be stopped and the analog output should be 0 V.
So the output signal should be 0V for as long as the start button is not pressed, then it should be a wave, when I press the start-button, for 10 seconds or less if the stop button is pressed before the end of the 10seconds.
s1 = daq.createSession('ni'); % create input session
ch1 = addAnalogInputChannel(s1,'Dev1', 0, 'Voltage'); % add analog channel for feedback of stim2 (trigger)
ch1.TerminalConfig = 'SingleEnded'; % ground the channel
addAnalogOutputChannel(s1,'Dev1',0,'Voltage'); % channel for sending stim1
s1.IsContinuous = true; % run till it is explicitely stopped
s1.Rate = inputRate;
I have a listener that makes a 0V signal if no data is queued.
lh = addlistener(s1,'DataRequired',@(src,event) src.queueOutputData(ZeroSignal));
And a listener that plots the input data in realtime in a figure.
lh1 = addlistener(s1,'DataAvailable',@(src,event) updateFigure(event.TimeStamps, event.Data));
Now my problem is that when I use the function stop(s1); to stop the sine wave, the whole sesion is stopped. And that's not what I want, I just want want the signal to go back to 0V. But I can only let the output signal be 0 after the whole queue is sent to the output.
Is there a way to empty the queue or replace the queue after the function queueOutputData is used?