How to use a (virtual) bus as input to a referenced model

9 vues (au cours des 30 derniers jours)
Marcus
Marcus le 5 Juin 2025
Commenté : Aabha le 10 Juin 2025
Ich am creating a virtual bus in a model which hosts a nested submodel.
I want to pass that virtual bus to the nested model which in turn shall have a single inport (In-)Block.
Unfortunately the input is not being recognized as being fed by a bus (i.e. when using a bus selector after the input port) no Elements are being shown when trying to simulate the model.
Is there a way to achieve that simulink detects the bus elements automatically once the models are being simulated together?
If not, what is the easiest way of exporting the information about the content of the virtual bus from the hosting model and import it to specify the the child models input?

Réponses (1)

Aabha
Aabha le 9 Juin 2025
Hi @Marcus,
I understand that you are using a virtual bus to pass data to a model reference. In Simulink, if you use a virtual bus as an input or an output for a referenced model, the bus cannot contain a variable-size signal element. This might be the reason behind the bus elements not being visible while using the bus selector block. For more details regarding model referencing signal requirements and limitations, please refer to the documentation link below: https://www.mathworks.com/help/releases/r2025a/simulink/ug/model-referencing-limitations.html#brazo0l
If you wish to transfer data to the referenced model using bus elements, you can convert the virtual bus to a non-virtual bus. The following documentation link shows an example in which a subsystem is converted to a referenced model, and bus elements are used as input to the referenced model: https://www.mathworks.com/help/releases/r2025a/simulink/slref/converting-subsystems-to-model-reference.html
Additionally, to create bus objects during the conversion of a subsystem to a model reference, you can use the Simulink.SubSystem.convertToModelReference function with the CreateBusObjectsForAllBuses argument set to true. Please refer to the documentation of the above function for more information: https://www.mathworks.com/help/releases/r2025a/simulink/slref/simulink.subsystem.converttomodelreference.html
I hope this helps.
  4 commentaires
Marcus
Marcus le 10 Juin 2025
Modifié(e) : Marcus le 10 Juin 2025
@Aabha I am using R2022b, so I cannot open your model. edit used R2024b to open it but the submodel is missing.
Please see my testmodels attached.
I neither can access the bus elements a/b in the nested model, nor the buselements x/y in the parent model.
When opening / double clicking the bus selectors, nothing is shown for elements in the bus.
Aabha
Aabha le 10 Juin 2025
The issue moght be that model 'b' was created first, with an input signal to the 'Bus Selector' block which was not a bus, and then referenced in the parent model. I tried replicating the same subsystem that you have created in 'b', and then converted it into a model reference using the following commands:
blk = "a/b1";
newmdl = "b1";
Simulink.SubSystem.convertToModelReference(blk,newmdl, ReplaceSubsystem = true);
This method seems to be working fine at my end.
I hope this is helpful to you.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Component-Based Modeling dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by