Lamp on App Designer does not work when I run simulation on Simulink

8 visualizzazioni (ultimi 30 giorni)
I am making an application to send and receive data in real time from a simulink model. By realtime I mean setting "inf" to "Stop time" not using the realtime toolbox.
So, my code works or I intend it to work as follows:
-With switch_1 start the simulation
-With switch_2 I send a "1" to a constant block in simulink and turn on a lamp in app designer.
The problem is that the lamp doesn't work when smiulink and app designer are running at the same time. Only when I run the app without simulink.
I have no idea why this happens, any other element works without problem. I hope you can help me.
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
app.Switch_1.Value = 0;
app.Switch_2.Value = 0;
set(app.Lamp1,'Color',[1 0 0]);
set(app.Lamp2,'Color',[1 0 0]);
set_param('Sim','SimulationCommand','stop');
end
% Value changed function: Switch_1
function Switch_1ValueChanged(app, event)
value = app.Switch_1.Value;
if value == 1
set_param('Sim','SimulationCommand','start')
elseif value == 0
set_param('Sim','SimulationCommand','stop')
end
end
% Value changed function: Switch_2
function Switch_2ValueChanged(app, event)
value = app.Switch_2.Value;
set_param([bdroot,'/Masa'],'Value', num2str(value));
if value == 1
set(app.Lamp1,'Color',[0 1 0]);
elseif value ==0
set(app.Lamp1,'Color',[1 0 0]);
end
end
end

Risposta accettata

Kojiro Saito
Kojiro Saito il 8 Lug 2022
drawnow might solve this.
For example,
if value == 1
set(app.Lamp1,'Color',[0 1 0]);
elseif value ==0
set(app.Lamp1,'Color',[1 0 0]);
end
drawnow

Più risposte (0)

Categorie

Scopri di più su Event Functions in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by