Passing a changing logical variable (boolean constant) to AppDesigner from Simulink during the simulation.

35 views (last 30 days)
I have already written a GUI in AppDesigner in which buttons are pressed to change logical variables in the Simulink model during the simulation. I have used an event listener in the subsystem callbacks to do this and it works fine. I now have to run some code in AppDesigner which depends on the state of a boolean constant (1 or 0 / true or false) in the Simulink model which changes during the simulation - I am doing this manually using a radio button (see pic).
The constant is connected to a subsystem using an input port (port number 1) as shown. In order to change a button icon, I am then trying to pick up the value in AppDesigner using the following code using rto.InputPort:
methods (Access = private)
function results = updateGUI(app, rto, b)
if ~isvalid(app) || (now-app.lastTime)*24*60*60 < 0.5
return
else
app.lastTime = now;
end
portData = rto.InputPort(1);
app.valve_open = portData;
if app.valve_open == 1
app.SB_1_Button.Icon = 'icon_1.jpg';
elseif app.valve_open == 0
app.SB_1_Button.Icon = 'icon_2.jpg';
end
end
end
I suspect my problem is something to do with the syntax of the "portData = rto.InputPort(1)" line. Either way, portData is not being picked up and hence the logic is not working. Any ideas anybody?
Kind Regards and Thanks
Neil

Accepted Answer

Neil
Neil on 21 Nov 2024 at 8:22
Thank you Gayathri. I shall try this.
Kind Regards
Neil

More Answers (1)

Gayathri
Gayathri on 20 Nov 2024 at 5:26
Hi @Neil,
I understand that you are trying to import a value from Simulink model into the App.
This can be done by directly getting the value in variable “rto” using the following command.
rto = get_param('Modelname/HP1_Blow_Valve','value');
The variable “rto” will contain the value ‘0’/’1' as a character value. So, we will have to convert it to a double value before storing it in “valve_open” and use it to set the icon of the “Button”. This can be implemented as shown below.
app.valve_open = str2double(rto);
if app.valve_open == 1
app.Button.Icon = 'icon_1.jpg';
else
app.Button.Icon = 'icon_2.jpg';
end
This would help set different icons for the “Button” depending on the value imported from the Simulink model.
For more information on “get_param” function, please refer to the following documentation link.
Hope you find this information helpful.

Products

Community Treasure Hunt

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

Start Hunting!