Effacer les filtres
Effacer les filtres

How to display the current value of a TagetPC-Signal in a numeric edit field (App Designer) and update the value automatically every timestep ?

3 vues (au cours des 30 derniers jours)
I tried to display a realtime value of my TargetPC on the app designer by the following code:
% Value changed function: AEditField
function AEditFieldValueChanged(app, event)
A= app.AEditField.Value;
app.AEditField.Value = getsignal(tg,'Path',1)
end
It works, but unfortunately i have to press enter in the EditField to update the value. I just want to display the current realtime value on my GUI.

Réponse acceptée

Jonas
Jonas le 14 Juil 2021
Inside the myTimerFcn, write:
app.AEditField.Value = getsignal(tg,'Path',1);
  1 commentaire
Heiko
Heiko le 14 Juil 2021
Thanks again for your help! I forgot to start the timer. Here is my code:
properties (Access = private)
%Timer Object
myTimer
end
methods (Access = private)
function myTimerFcn(app, ~, event)
%Get value for edit field
tg = slrealtime('TargetPC1');
app.AEditField.Value = getsignal(tg,'Path',1);
%Start timer (This can be also done with a button callback)
start(app.myTimer);
end
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
% Create timer object
app.myTimer = timer(...
'ExecutionMode', 'fixedRate', ... % Run timer repeatedly
'Period', 0.5, ... % Period is 0.5 seconds
'BusyMode', 'queue',... % Queue timer callbacks when busy
'TimerFcn', @app.myTimerFcn); % Callback that runs every period
end
% Value changed function: AEditField
function AEditFieldValueChanged(app, event)
end
end

Connectez-vous pour commenter.

Plus de réponses (1)

Jonas
Jonas le 9 Juil 2021
  1 commentaire
Heiko
Heiko le 12 Juil 2021
Thanks Jonas for the quick response and the input with the timer object, but I have still some
understanding problems.
I tried to generate my timer like this:
properties (Access = private)
myTimer % Description
end
methods (Access = private)
function myTimerFcn(app,~,~)
???
end
end
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
% Create timer object
app.myTimer = timer(...
'ExecutionMode', 'fixedRate', ... % Run timer repeatedly
'Period', 1, ... % Period is 1 second
'TimerFcn', @app.myTimerFcn); % Specify callback function
end
...
How to assign my value to the EditField in that function?

Connectez-vous pour commenter.

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by