フィルターのクリア

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

4 ビュー (過去 30 日間)
Fer_pg
Fer_pg 2022 年 7 月 7 日
コメント済み: Fer_pg 2022 年 7 月 8 日
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 Center および File ExchangeEvent Functions についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by