Use Simulink Bus Objects
After you create a Simulink.Bus object and specify its attributes,
you can associate it with a block or object that needs the bus definition. For
information on whether to use bus objects, see Define Bus Properties for Reuse. For information on how to create bus objects, see
Create Simulink Bus Objects.
Before you simulate a model, the bus objects that the model uses must be loaded into the base workspace or a data dictionary used by the model.
Specify Simulink Bus Objects as Data Types
To specify bus properties, you can use a Simulink.Bus object for
these blocks and objects:
Bus Creator block
Constant block
Data Store Memory block
In Bus Element block
Inport block
Out Bus Element block
Outport block
Signal Specification block
Simulink.BusElementobjectSimulink.ParameterobjectSimulink.Signalobject
To associate a block or object with a bus object, set the data type of the block
or object to Bus: <object name> and replace
<object name> with the
Simulink.Bus object name. When you set the data type of a
Simulink.BusElement object to a Simulink.Bus
object, the Bus: prefix is optional.
For an example that specifies a bus object via a port block, see Specify Reusable Bus Properties at Bus Element Port.
When you specify a bus object as a data type of a block or object, the properties specified by the bus object typically override the properties specified by the block or object.
For example, suppose a Signal Specification block has these settings:
Unit set to
ft/sData type set to a
Simulink.Busobject with elements that specify a unit ofm/s
The Signal Specification block uses
m/s as the unit for the bus elements.
Save Simulink Bus Objects
You can save Simulink.Bus objects to these locations:
Data dictionaries
Functions
MAT files
Databases or other external files
If you do not save bus objects, then when you reopen a model that uses the bus objects, you must create the bus objects again.
Choose where to store bus objects based on your modeling requirements.
| Modeling Requirement | Location |
|---|---|
| Store data for large models and model hierarchies. | Use a data dictionary. When you save to a
data dictionary from the base workspace, you get all the
variables used by the model, not just the
To save changes to a data dictionary, use the Type Editor or Model Explorer. To update a model to use a data dictionary, see Migrate Models to Use Simulink Data Dictionary. |
| Use MATLAB® for traceability and model differencing. | Use a script or function. To create a
script or function that defines one or more
|
| Save and load bus objects faster. | Use a MAT file. To create a MAT file that
contains |
| Compare bus interface information with design documents stored in an external data source | Use a database or other external files. Use
the |
To save bus objects stored in the base workspace, you can use any MATLAB technique that saves the contents of the base workspace. However, the resulting file contains everything in the base workspace, not only bus objects.
Map Simulink Bus Objects to Models
Mapping bus objects to models helps to facilitate automation and consistency across models.
By identifying the bus objects that a model requires, you can check that those objects are loaded before model execution.
By identifying the models that use a bus object, you can check that changes to a bus object do not cause unexpected changes in models that use the bus object.
To load the bus objects before model execution, consider these approaches:
Projects — Automatically load or run files that define bus objects by configuring the files to run when you open a project. For details, see Project Management.
Data dictionaries — Store bus objects with variables and other objects for one or more models. To share a bus object among models, you can link each model to a dictionary and create a common referenced dictionary to store the object. For an example, see Partition Dictionary Data Using Referenced Dictionaries.
Databases — Capture mapping information in an external data source, such as a database.
Model callbacks — Load or run files that define bus objects by using a model callback, such as
PreLoadFcn. If a model uses only a few bus objects, consider copying the bus object code directly into the callback, instead of loading a file. For more information, see Model Callbacks.
To find where an open model uses a bus object, see Finding Blocks That Use a Specific Variable.
Tip
Using a rigorous and standard naming convention is helpful for mapping bus
object usage. For example, consider the model and data required for an actuator
control function. Naming the model Actuator and the input and
output ports ActuatorBusIn and
ActuatorBusOut, respectively, makes the connection
between the bus objects and the model clear.
Note that this approach can cause issues if the output from one model is fed directly to another model. In this case, the naming mismatch results in an error.
Modify Simulink Bus Objects
During model development, you can modify buses to match bus objects or modify bus objects to match buses. If you do not want to change the bus object, you can:
Create a bus object that matches the changes to the bus and use the new bus object for the blocks that the changed bus connects to.
Revert the bus changes so that the bus continues to match the associated bus object.
When you modify bus objects, you must resave them to keep the changes.