Timer "Busymode" "queue" not finishing TimerFcn

1 回表示 (過去 30 日間)
Tobias Geib
Tobias Geib 2018 年 6 月 22 日
回答済み: Geoff Hayes 2020 年 3 月 31 日
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?

回答 (1 件)

Geoff Hayes
Geoff Hayes 2020 年 3 月 31 日
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

カテゴリ

Help Center および File ExchangeCode Execution についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by