How to get the port types and dimensions for a block
Show older comments
We are generating code using RTW via a script. I am trying to collect the port dimensions and data types. Argument names would be great too, but not required.
I am currently able to get the port names
Accepted Answer
More Answers (4)
Nirmal Gunaseelan
on 2 Jun 2011
You can get the dimensions and data types of a block's port after you put the model into a 'compiled' state. The
model([],[],[],'compile')
where model is your model name will get you there. After that, a get_param on the block of interest with the options
CompiledPortDimensions
CompiledPortDataTypes
will get you the info you want.
3 Comments
Fangjun Jiang
on 2 Jun 2011
Good to know this model([],[],[],'compile') approach! From what version of Simulink can I do this?
Kevin
on 2 Jun 2011
Nirmal Gunaseelan
on 3 Jun 2011
'model' in the above snippet is the name of your loaded model. I like to think of it as a way to interact with the model as though it has a function signature.
I have been using this snippet for a long time now, I believe it was there as far back as R14.
Kevin
on 2 Jun 2011
0 votes
Fangjun Jiang
on 2 Jun 2011
0 votes
Some properties such as dimensions and data types are not up to date when the model is loaded. These properties depend on other information. They also need to be cross-checked to avoid any miss-match. You need to "update" the model or further force the model to be "compiled" to go through those propagation and cross-checking. The command model([],[],[],'compile') is to force that process. model is not a handle. It is the name of your model. The model needs to be loaded. Once the command model([],[],[],'compile') is done. You can use find_system() with 'SearchDepth' to find all the root-level Inport blocks and Output blocks. And then you can get the dimension and data type property of all those Inport/Outport blocks.
5 Comments
Kevin
on 2 Jun 2011
Walter Roberson
on 2 Jun 2011
Kevin, does lcInportNames return valid looking names? Do Inport always have to be named or are they sometimes nameless?
Fangjun Jiang
on 2 Jun 2011
You code looks good. I am off Matlab now so won't be able to confirm it for you. Do this to do a quick test-run.
Select an Inport block at your model root level by just clicking it. Go to Matlab command window and type get(gcbh). You'll see a long list of properties and their values. Check whether 'CompiledPortDiemsios' is the exact right property name. Remember you need to run that model(...) command first.
Kevin
on 2 Jun 2011
Kevin
on 2 Jun 2011
Kevin
on 2 Jun 2011
3 Comments
Nirmal Gunaseelan
on 3 Jun 2011
Kevin, the data type of the port is the name of the bus. This bus object should be thought of as the data type specification in the workspace. When you EVAL this data type name, you'll be getting the bus object. You could then access its type (Simulink.Bus) using CLASS (Bus/primitive) and its elements (Simulink.BusElement) and their data types and so on (buses could have other buses as its elements). I agree that the bus type is making the process of finding the data type complicated.
Fabien Jeanneteau Safran
on 11 May 2022
Hi,
If you are stuck (like me), you should try:
model([],[],[],'term')
I found answer on following page: https://fr.mathworks.com/matlabcentral/answers/29764-turn-off-compile-mode
Regards,
Fabien
Categories
Find more on Event Functions in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!