|
From: Sean on 18 Jun 2008 17:43 Hello all And thanks ahead for your time, I have a gui that is supposed to display input from a Nidaq device in real time. I wish for it to do this as long as the gui is up and running. What I have now is a call in my main gui file opening function to start the input: main_OpeningFcn(hObject, eventdata, handles, varargin) setappdata(0, 'fhupdate_feedback', @update_feedback); analog_feedback() %%% Analog_feedback() then sets all of the trigger parameters etc.: %Stop running DAQ processes. if(~isempty(daqfind)) stop(daqfind) end %Get analog input device and add channels. ai = analoginput('nidaq', 'Dev1'); addchannel(ai, 0:1); %Set trigger parameters. set(ai, 'SampleRate', 2000); set(ai, 'TriggerType', 'immediate'); set(ai, 'SamplesPerTrigger', 2000); set(ai, 'TriggerRepeat', 0); %Set timer parameters. set(ai, 'TimerPeriod', .5); set(ai, 'TimerFcn', {@daq_peek}); set(ai, {'StartFcn', 'StopFcn', 'TriggerFcn'}, {'','',''}); %Start acquiring data. start(ai) %%%%%% %%%%%%%% daq_peek(obj, event) %saves the data and transmits it back to the main_gui persistent data; persistent load_cell; size1 = min(floor((obj.SampleRate)* (obj.Timerperiod)),obj.SamplesAvailable); data = cat(1, data, peekdata(obj, size1)); load_cell = data(:,1); displacement_1 = data(:, 2); setappdata(0, 'displacement_1', displacement_1); setappdata(0, 'load_cell', load_cell); fhupdate_feedback = getappdata(0, 'fhupdate_feedback'); feval(fhupdate_feedback); %%%% I have the triggerepreat set at 0 so ideally this opening function should get 2000 samples sent back to it and if I set the repeat to inf it would run infinitely just as I want. However, it instead repeatedly runs to a number based on the samplespertrigger (regardless of triggerrepeat setting). With 2000 samples per trigger it runs to 16384 samples and with 4000 samples per trigger it runs to 32768. It then stops and when I attempt to close the gui it gives me a "Warning object stopped before being deleted". This makes sense because I never stopped ai. It then gives me a fatal error of "could not find handle in my main gui" which once again makes sense because the gui was deleted. So what am I missing to make it run infinitely and how do I stop it with the closerequest function to avoid the fatal error? Also, I'm running R2007b 7.5.0. Thanks again, -Sean
From: Sherryl Radbil on 19 Jun 2008 08:47 Hi Sean, What do you mean by "It runs to 16384 samples"? Where is this number coming from? The fact that you're getting "Warning object stopped before being deleted" means that the AI object keeps running, so I would expect that if you examine the AI's SamplesAvailable property over time you'd see it continue to grow. Out of curiosity, which device are you using? I've adapted the code you posted as a small, non-GUI program and ran with a simulated NI device and found that it runs until I specifically stop it. The code and a snippet of the result is below. Try this code and if you still see it "stopping" there may be an interaction with your GUI that must be considered. Sherryl ADAPTED CODE: function dothis %Stop running DAQ processes. if(~isempty(daqfind)) stop(daqfind) delete(daqfind) % It is important to delete unused object to free resources end %Get analog input device and add channels. ai = analoginput('nidaq', 'Dev1'); addchannel(ai, 0:1); %Set trigger parameters. set(ai, 'SampleRate', 2000); set(ai, 'TriggerType', 'immediate'); set(ai, 'SamplesPerTrigger', 2000); set(ai, 'TriggerRepeat', Inf); %Set timer parameters. set(ai, 'TimerPeriod', .5); set(ai, 'TimerFcn', {@daq_peek}); set(ai, {'StartFcn', 'StopFcn', 'TriggerFcn'}, {'','',''}); %Start acquiring data. start(ai) %%%%%% end %%%%%%%% function daq_peek(obj, event) %#ok<INUSD> %saves the data and transmits it back to the main_gui persistent data; size1 = min(floor((obj.SampleRate)* (obj.Timerperiod)),obj.SamplesAvailable); data = cat(1, data, peekdata(obj, size1)); fprintf('%s %5d %d\n', datestr(now, 'HH:MM:SS.FFF'), size1, obj.SamplesAvailable) end MY RESULTS: 08:41:53.385 1000 16384 08:41:53.885 1000 17408 08:41:54.385 1000 18432 08:41:54.885 1000 19456 08:41:55.385 1000 20480 08:41:55.885 1000 21504 08:41:56.385 1000 22528 08:41:56.885 1000 23552 08:41:57.385 1000 24576 08:41:57.885 1000 25600 >> stop(daqfind)
From: Sean on 19 Jun 2008 12:30 "Sherryl Radbil" <sherryl.radbil.dontspamme(a)mathworks.com> > function dothis > > %Stop running DAQ processes. > if(~isempty(daqfind)) > stop(daqfind) > delete(daqfind) % It is important to delete unused > object to free resources > end > > %Get analog input device and add channels. > ai = analoginput('nidaq', 'Dev1'); > addchannel(ai, 0:1); > > %Set trigger parameters. > set(ai, 'SampleRate', 2000); > set(ai, 'TriggerType', 'immediate'); > set(ai, 'SamplesPerTrigger', 2000); > set(ai, 'TriggerRepeat', Inf); > > %Set timer parameters. > set(ai, 'TimerPeriod', .5); > set(ai, 'TimerFcn', {@daq_peek}); > set(ai, {'StartFcn', 'StopFcn', 'TriggerFcn'}, {'','',''}); > > > %Start acquiring data. > start(ai) > %%%%%% > > end ^^^^ ^^^^ Thanks a lot Sherryl!! The problem was I was missing the end right there. Those three letters absorbed about 8hrs of my life. Thank you again.
|
Pages: 1 Prev: imline (R2007a) wait resume Next: XOR 2 matrices with decimal values |