MATLAB Answers

Timer "Busymode" "queue" not finishing TimerFcn

2 views (last 30 days)
Tobias Geib
Tobias Geib on 22 Jun 2018
Answered: Geoff Hayes on 31 Mar 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?

  0 Comments

Sign in to comment.

Answers (1)

Geoff Hayes
Geoff Hayes on 31 Mar 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

  0 Comments

Sign in to comment.

Sign in to answer this question.

Products


Release

R2017b