I have some trouble to start a data acquistion within my app made with app designer. Basically the overall behaviour of the app is:
- playing a noise
- Display a Question
- The user will repply by 'yes' or 'no' via two button in a box. This box is plug to my NI daq card.
- When the user repplied, the app start another noise
a bit of a code: Play Button:
[y,Fs] = audioread([app.dir '\audio\track' num2str(app.index) '.wav']);
tone = audioplayer(y,Fs);
app.PlayButton.Enable = 'off';
app.ThenoiseisplayingLabel.Visible = 'on';
app.Lamp.Visible = 'on';
app.Lamp.Visible = 'off';
And 'testboitier' is my function used to collect the data and save them Code:
methods (Access = public)
function stopWhenExceedOneV(src, event)
if any(event.Data(1,1) > 4.0 || event.Data(1,2) > 4.0)
disp('Event listener: No')
disp('Event listener: Yes')
disp('Event listener: Continuing to acquire')
s = daq.createSession('ni');
ch1 = addAnalogInputChannel(s, 'cDAQ1Mod1', 0, 'Voltage');
ch2 = addAnalogInputChannel(s, 'cDAQ1Mod1', 1, 'Voltage');
s.Rate = 51200;
s.IsNotifyWhenDataAvailableExceedsAuto = true;
lh = addlistener(s,'DataAvailable', @stopWhenExceedOneV);
s.IsContinuous = true;
StopWhenexceedoneV will stop the acquisition and save the data.
I tested those two function and they are working when they aren't used within an App. EDIT: saving the data is not working either finally..
Does someone have an idea about how to fix this ? Furthermore if someone can explain to me why it doesn't work I would be very grateful as I think I will have some other app to make like that
Thank you !