Appdesigner EditField not updating while simulink model is running

2 views (last 30 days)
Hi
I am attempting to create an app which continusouly runs a simulink model and updates editfields in the application to match current simulink data. To do this I have a model with infinite runtime and an application with a timer that periodically pulls the 'Value' parameter of a constant block. The timer runs and pulls the requested data (tested by printing to cmd windwow) however it is not updating the editfield while the model is running.
I have the model set up for simulink realtime but I have confirmed that is not the issue as it runs the same in normal mode as well. I've also tried running the model/timer at several rates which seems to make no impact.
When run the timer seems to work and update vlaues for a short period of time before the model fully initalizes and then stops so I know that the code is capable of correctly updating the expected fields. Any advice on how to get those fields to update while the model is active?
While running:
While stopped:
properties (Access = private)
CurrentState = 0; % Last button press state
Updater % Object to hold update timer
end
methods (Access = private)
function getstate(app,~,~)
app.TimerCheckEditField.Value = app.TimerCheckEditField.Value+1; % Check to see how many times the timer has run
LampVal = str2double(get_param(['RealTimeAppInterface','/ConFlip'],'Value')); % Get the value of the constant block
app.ValEditField.Value = LampVal; % Set the 'Val' editfield to the current block value
if LampVal % Change lamp color depnding on value
app.Lamp.Color = [0 1 0];
else
app.Lamp.Color = [1 0 0];
end
end
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
set_param('RealTimeAppInterface', 'SimulationCommand', 'start') % Start the model
app.Updater = timer('Period',1/10,'ExecutionMode','fixedRate','TasksToExecute', Inf); % Set up update timer
app.Updater.TimerFcn = @app.getstate; % Set up timer funtion
start(app.Updater)

Accepted Answer

Image Analyst
Image Analyst on 18 Jul 2022
Try throwing in a
drawnow
somewhere to force an immediate screen update.

More Answers (0)

Categories

Find more on Real-Time Simulation and Testing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!