Lamp on App Designer does not work when I run simulation on Simulink
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponse acceptée
Kojiro Saito
le 8 Juil 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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Event Functions dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!