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

12 ビュー (過去 30 日間)
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.

採用された回答

Jonas
Jonas 2021 年 7 月 14 日
Inside the myTimerFcn, write:
app.AEditField.Value = getsignal(tg,'Path',1);
  1 件のコメント
Heiko
Heiko 2021 年 7 月 14 日
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

サインインしてコメントする。

その他の回答 (1 件)

Jonas
Jonas 2021 年 7 月 9 日
  1 件のコメント
Heiko
Heiko 2021 年 7 月 12 日
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?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTarget Computer Setup についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by