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

9 次查看(过去 30 天)
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

采纳的回答

Kojiro Saito
Kojiro Saito 2022-7-8
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Event Functions 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by