Lamp on App Designer does not work when I run simulation on Simulink
조회 수: 8 (최근 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
댓글 수: 0
채택된 답변
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 Exchange에서 Event Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!