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

4 views (last 30 days)
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.

Accepted Answer

Jonas
Jonas on 14 Jul 2021
Inside the myTimerFcn, write:
app.AEditField.Value = getsignal(tg,'Path',1);
  1 Comment
Heiko
Heiko on 14 Jul 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

Sign in to comment.

More Answers (1)

Jonas
Jonas on 9 Jul 2021
  1 Comment
Heiko
Heiko on 12 Jul 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?

Sign in to comment.

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!