Azzera filtri
Azzera filtri

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

23 visualizzazioni (ultimi 30 giorni)
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.

Risposte (1)

Walter Roberson
Walter Roberson il 12 Lug 2024 alle 22:29
Modificato: Walter Roberson il 12 Lug 2024 alle 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 Commenti
Gustavo
Gustavo il 13 Lug 2024 alle 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 il 13 Lug 2024 alle 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!

Accedi per commentare.

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by