Export bus datatype from referenced subsystem
Show older comments
I have created a nested bus in a referenced subsystem in simulink and would like to use the bus datatype again in a different model. For this i would like to export the datatype from simulink to a dataDictionary. I tried to open the referenced subsystem in a model and use the commands Simulink.Bus.createObject and Simulink.Bus.save. But i was not able to generate the object in matlab to save it afterwards. Is there a easier solution to this?
9 Comments
Fangjun Jiang
on 8 May 2024
Why not and what is the error or message? If not supported by referenced subsystem, I can think of the last resort is to copy the subsystem to a model. I believe the whole model has to pass model update to create the bus object.
Lukas
on 10 May 2024
Lukas
on 10 May 2024
Fangjun Jiang
on 10 May 2024
That is what I mean "the whole model has to pass model update to create the bus object.". Your model has to have the real content for that bus structure and the model has to be error free.
Fangjun Jiang
on 10 May 2024
Now I am lost. You said "It works, if i create a new simulink model with just some constant and sine inputs to a nested bus". Were you able to do it on your real model?
Lukas
on 13 May 2024
Fangjun Jiang
on 13 May 2024
That is weird. No more advice other than trying on the real model. Maybe contact the Mathworks tech support.
Lukas
on 13 May 2024
Answers (1)
Yatharth
on 22 May 2024
Hi Lukas,
In your given code :
mdl = "BusHierarchy";
block = "BusHierarchy/Bus Creator1";
load_system(mdl)
busInfo = Simulink.Bus.createObject(mdl,block);
file1 = "DefaultFunction";
Simulink.Bus.save(file1); -> This command lead to an default matlab file without any content of the Bus Creator1
I am not able to figure out what is your referenced sub-system?
I will share my process and code for your reference:
1. Opening a Bus Object creation example
openExample('simulink/CreateSimulinkBusObjectFromBlockExample')
2. Modifying the BusObjectCreationModel.slx : I selected everything and right clicked to make a Subsystem named SS1
3. Modifying the CreateSimulinkBusObjectFromBlockExample.mlx file:
open_system('BusObjectCreationModel')
%Create a Bus object that corresponds with the bus created by the Bus Creator block.
busInfo = Simulink.Bus.createObject('BusObjectCreationModel','BusObjectCreationModel/SS1/Bus Creator'); %here I have added SS1 in the block path
Simulink.Bus.save('BusObjectFunctionCellFormat'); % here I have added the bus.save function to generate the BusObjectCreationModel.slx
Here is the documentation for the Simulink.Bus.save https://www.mathworks.com/help/simulink/slref/simulink.bus.save.html
You can also directly save it to a file while creating the Bus object refer to this link highlight: https://www.mathworks.com/help/simulink/slref/simulink.bus.createobject.html#:~:text=Create%20Simulink.Bus%20objects%20from%20the%20Bus%20Creator%20block%20named%20Bus%20Creator1.%20This%20block%20receives%20input%20from%20a%20source%20block%20and%20another%20Bus%20Creator%20block.%20To%20save%20the%20Simulink.Bus%20object%20definitions%20in%20a%20function%2C%20also%20specify%20a%20filename.
Categories
Find more on Subsystems in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!