필터 지우기
필터 지우기

Error message when using timers in AppDesigner after a few seconds running

조회 수: 23 (최근 30일)
Gustavo
Gustavo 2024년 7월 12일 21:38
댓글: Gustavo 2024년 7월 13일 11:30
I'm quite new to using timers in Matlab, and currently I'm running a project that will need them to continuously update some info in our App Designer window. The problem is, I followed the instructions in this tutorial from Matlab and initially my timer and callback function work normally. But after some time of it running I receive the following error message:
Error while evaluating TimerFcn for timer 'timer-1'
Not enough input arguments.
I currently initialize my timer in the startupFcn of the app as:
function startupFcn(app)
global params
app.textbox_Log.Value = {'Start'};
app.timerCounter1sec = 0;
app.timerCounter10sec = 0;
app.logStatus = 'running';
app.timer500ms = timer('Period',0.5,...
'ExecutionMode', 'fixedSpacing', ...
'TasksToExecute', Inf, ...
'BusyMode', 'drop', ...
'TimerFcn', @app.timerTest);
start(app.timer500ms);
updateJobList(app, params);
fillJobsTable(app, params);
end
And my callback function is defined as the following (I will omit the code for now since I don't think it's that important right now):
function timerTest(app,~,~)
% Function details...
end
Can someone help me with this? I have no clue of what is happening to throw this error in the timer, even considering that it works for around 3-4 seconds before breaking.

답변 (1개)

Walter Roberson
Walter Roberson 2024년 7월 12일 22:29
편집: Walter Roberson 2024년 7월 12일 22:30
'TimerFcn', @app.timerTest);
the timer will be created with a TimerFcn that is a function handle to a function that expects two parameters.
function timerTest(app,~,~)
You define the function as expecting three parameters.
Note that timer functions are not passed app by default.
  댓글 수: 2
Gustavo
Gustavo 2024년 7월 13일 10:11
But according to this question https://de.mathworks.com/matlabcentral/answers/346703-how-to-use-timer-callback-in-app-designer the way I've coded it, by passing the app parameter to the function and calling it as app.timerTest should work well. And the strange thing is that it does work well, but for a short period of time. It makes no sense for me how during around 4 seconds there are all the necessary parameters, and then out of nowhere it breaks by lack of parameters.
I've also tried this implemententation https://de.mathworks.com/matlabcentral/answers/1615070-how-can-i-implement-a-timed-counter-in-app-designer with the callback function inside of the startup function to avoid having to pass the app object, but the same happens, it runs for some seconds and then yields the same error message.
Gustavo
Gustavo 2024년 7월 13일 11:30
I think I actually found the problem by organizing my code. It seems it had not much to do with the actual usage of the timer, but rather the way I was working with the callback function. I was accessing my global variable "param" inside of the callback, I've now simplified my app to store the "param" variable as a property of the app and the problem was solved, no more error messages comming from the timer.
Thanks for the help!

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

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by