It is possible to get the number and name of ports in a protected simulink model?

38 visualizaciones (últimos 30 días)
Hello,
I have a protected model (.slxp) in simulink with 150 inputs and 50 outputs, and a I need to automatize the process of connecting them to other blocks input/outputs. Im trying to get a 2 columns matrix with the string name of the port and the number associated. And later, use the add_line command in a script to connect to others blocks.
I have tried this with a compilated simple model with less inputs/outputs and i get a matrix cell like the following:
block_InPortInfo =
'Speed' '1'
'Time' '2'
'On' '3'
And the code I used is:
block = get_param('Compiled/Block','Handle');
block_handles = find_system(block,'LookUnderMasks', 'on', 'FollowLinks', 'on', 'SearchDepth', 1, 'BlockType', 'Inport');
block_InPortInfo = [get_param(block_handles, 'Name') get_param(block_handles, 'port') ];
But if I use this code with a protected simulink block the variable
block_handles
is empty [ ].
Is there any way I can retrieve this information of the ports of a protected block in simulink?
Thanks.

Respuestas (1)

Bhargavi Maganuru
Bhargavi Maganuru el 12 de Feb. de 2020
You can try using ‘PortHandles’ block property
%Get port Handles
block=get_param(Compiled/Block,'PortHandles');
%Get port Info
block_InPortInfo = [get_param(block.Inport,'PortType') , get_param(block.Inport,'PortNumber') ];
  1 comentario
svanimisetti
svanimisetti el 29 de Mzo. de 2022
@Bhargavi Maganuru - your solution on gives the port type and number. How can I extract the name. I have a fairly large protected model with many inport/outports. I would like to extract the names of these ports. Using find_system+LookUnderMasks is not a viable option for protected models. Is there another option to programatically get port names for protected models.

Iniciar sesión para comentar.

Categorías

Más información sobre Programmatic Model Editing en Help Center y File Exchange.

Productos


Versión

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by