Timer stop function // findobj returns nothing

1 回表示 (過去 30 日間)
Adrian
Adrian 2013 年 10 月 8 日
コメント済み: Adrian 2013 年 10 月 8 日
Hi, I constructed a timer to run a countdown, at the beginning of the countdown I want to turn a UserData variable to 'on'. At the end of the countdown I want it back to 'off'. My actuall code looks like that:
t = timer('Period', 1, 'TasksToExecute', stop_in_sec, 'ExecutionMode', 'fixedRate', 'ObjectVisibility', 'off');
t.StartFcn = { @run_timer, handles.Countdown_edit, 'Countdown started:'};
t.StopFcn = { @run_timer, handles.Countdown_edit, 'Countdown stopped'};
t.TimerFcn = { @run_timer, handles.Countdown_edit, ''};
t.UserData = stop_in_sec;
start(t)
and the timer callback:
function run_timer(t,event,Countdown_edit, varargin)
switch event.Type
case 'StopFcn'
Schalter = get(findobj('Tag', 'LiveCam_Tool'), 'UserData');
Schalter.xyz = 'on';
set(Countdown_edit, 'str', '-----');
delete(t);
case 'StartFcn'
Schalter = get(findobj('Tag', 'LiveCam_Tool'), 'UserData');
Schalter.xyz = 'off';
case 'TimerFcn'
set(Countdown_edit, 'str', t.UserData);
t.UserData= t.UserData-1;
end
After placing breakpoints in StopFcn, StartFcn and TimerFcn the programm was running. If I just place them in one or two Fcn's the "get(findobj('Tag', 'LiveCam_Tool'), 'UserData');" in StopFcn returns nothing. (The same in the StartFcn is still working!) Who can help me?

回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 10 月 8 日
The object might have a hidden handle, or might have a handle visible in callbacks. Try replacing findobj() with findall()
  1 件のコメント
Adrian
Adrian 2013 年 10 月 8 日
It tells me: Invalid handles passed to findall.
And now its not even running with breakpoints.

サインインしてコメントする。

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by