Timer "Busymode" "queue" not finishing TimerFcn

1 Ansicht (letzte 30 Tage)
Tobias Geib
Tobias Geib am 22 Jun. 2018
Beantwortet: Geoff Hayes am 31 Mär. 2020
Hello, i am trying to get a Timer running, while using Busymode, queue. The issue is regarding the fact, that is seems as though my TimerFcn does not finish. Thus, the timer object only ever calls the TimerFcn once and then does not repeat it after it finished.
I have been trying to get minimal example to work:
function gui_OpeningFcn(hObject, eventdata, handles, varargin)
MyTimer = timer(...
'BusyMode', 'queue', ...
'Period', 1, ...
'TimerFcn', {@test});
set(MyTimer,'tag','MyTimer')
end
function buttonCallback(hObject, eventdata, handles)
MyTimer=timerfind('tag','MyTimer');
start(MyTimer);
end
function test(obj, event)
MyTimer=timerfind('tag','MyTimer');
disp(MyTimer.TasksExecuted)
drawnow
end
As output I accordingly only get
1
Could someone kindly guide me towards a right direction, how to get the TimerFcn to finish and have the next task executed?

Antworten (1)

Geoff Hayes
Geoff Hayes am 31 Mär. 2020
Tobias - it has been a couple of years but...the default execution mode for a timer is "single shot", so the timer will just fire once. If you want the timer to fire periodically (in your case, every one second) then you need to change the execution mode (see timer for details) to (say) "fixed rate"
MyTimer = timer(...
'BusyMode', 'queue', ...
'Period', 1, ...
'ExecutionMode', 'fixedRate', ...
'TimerFcn', {@test});
By the way, the handles structure can be used to store the timer so that the other callbacks can access it through there (rather than using timerfind
function gui_OpeningFcn(hObject, eventdata, handles, varargin)
handles.MyTimer = timer(...
'BusyMode', 'queue', ...
'Period', 1, ...
'ExecutionMode', 'fixedRate', ...
'TimerFcn', {@test});
guidata(hObject, handles);
function buttonCallback(hObject, eventdata, handles)
start(handles.MyTimer );
function test(obj, event)
disp(obj.TasksExecuted)
drawnow
end

Kategorien

Mehr zu Code Execution finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by