Timer "Busymode" "queue" not finishing TimerFcn

1 visualización (últimos 30 días)
Tobias Geib
Tobias Geib el 22 de Jun. de 2018
Respondida: Geoff Hayes el 31 de Mzo. de 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?

Respuestas (1)

Geoff Hayes
Geoff Hayes el 31 de Mzo. de 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

Categorías

Más información sobre Code Execution en Help Center y File Exchange.

Productos


Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by