타이머 오류 시 자동 재시작

조회 수: 7 (최근 30일)
Hyun-yong Kim
Hyun-yong Kim 2020년 9월 3일
댓글: Hyun-yong Kim 2020년 9월 17일
타이머로 특정루틴을 계속 실행해야 하는데,
가끔씩 타이머가 원인불명으로 중단되는 경우가 발생합니다.
이처럼 어떤 오류로 타이머가 중단된 경우,
이를 감지하여 타이머를 다시 실행시키고 싶습니다.
좋은 방법이 있을까요?
  댓글 수: 2
madhan ravi
madhan ravi 2020년 9월 3일
Simulink?
Hyun-yong Kim
Hyun-yong Kim 2020년 9월 4일
I'm using MATLAB
I will try to the following code. Is it OK?
---------------------------------------------------
try
timer_processing_routine
catch
t = timerfind;
if isempty(t)
t = timer .... % redefind the timer
elseif t.Running == "off"
start(t)
end
end
-------------------------------------------------------

댓글을 달려면 로그인하십시오.

채택된 답변

Sourabh Kondapaka
Sourabh Kondapaka 2020년 9월 17일
Hi,
As I am unaware with what error the timer has stopped, your code should also work.
You can use the below code as a reference if required:
%Here the timer runs for every 1 second for ever.
t = timer;
t.ExecutionMode = 'fixedSpacing';
t.Period = 1;
t.TimerFcn = @check;
start(t)
function check(~, ~)
count = timerfind;
if isempty(count)
t = timer;
t.ExecutionMode = 'fixedSpacing';
t.Period = 1;
t.TimerFcn = @check;
start(t)
else
% Your Timer processing routine here
disp("Timer processing routine");
end
end
  댓글 수: 1
Hyun-yong Kim
Hyun-yong Kim 2020년 9월 17일
Thank you very much for your help.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Octave에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!