A bus can have an associated bus object, which provides properties that Simulink® uses to validate the bus signal. Bus objects are optional for virtual buses, but required for nonvirtual buses.
A bus object specifies only the architectural properties of a bus, as distinct from the values of the signals it contains. For example, a bus object can specify the number of elements in a bus, the order of those elements, whether and how elements are nested, and the data types of constituent signals; but not the signal values. A bus object is analogous to a structure definition in C: it defines the members of the bus but does not create a bus. Another way of thinking of a bus object is that it is similar to a cable connector. The connector defines all the pins and their configuration and controls what types of wires can be connected to it. Similarly, a bus object defines the configuration and properties of the signals that the associated bus must have.
A bus object is an instance of class
Simulink.Bus that can be stored in a location such as the base workspace.
The object defines the structure of the bus and the properties of its elements, such as
nesting, data type, and size.
A bus object serves as the root of an ordered hierarchy of bus elements, which are
instances of class
Simulink.BusElement. Each element
completely specifies the properties of a signal in a bus, such as its name, data type,
and dimensionality. The order of the elements contained in the bus object defines the
order of the signals in the bus. A bus object can also specify properties that were not
defined by constituent signals, but were left to be inherited.
You can use the Simulink Bus Editor to create and manage bus objects, as described in Create Bus Objects with the Bus Editor, or you can use the Simulink API, as described in Create Bus Objects Programmatically. After you create a bus object and specify its attributes, you can associate it with any block that needs to use the bus definition that the object provides.
You can save bus objects as MATLAB® code or as a MAT-file.
You must use bus objects for these modeling configurations:
Nonvirtual buses that cross model reference boundaries
MATLAB Function block or Stateflow® charts that input or output buses
S-function or Legacy Code Tool interface with external code
If you use Bus Creator block parameters to specify bus signal properties, all blocks downstream from the bus inherit the same properties.
You can use Bus Creator block parameters to define virtual buses and perform limited error checking. To perform thorough error checking on a bus, associate a bus object with that bus. Using bus objects to check bus signals for errors is important when you want to create reusable and shareable model components.
To make it easier to trace the correspondence between the model and the generated code for a bus, use a nonvirtual bus. The generated code for a nonvirtual bus produces a structure, but also can result in multiple copies of some bus signals.
You can associate a bus object with several blocks. Some blocks require that you specify a bus object if the block has a bus input or bus output. When a bus object governs a signal output by a block, the signal is a bus that has exactly the properties specified by the object. When a bus object governs a signal input by a block, the signal must be a bus that has exactly the properties specified by the object. Any variance causes an error.
|Block||Requires Bus Object for Bus Input or Output|
|Data Store Memory|
|Data Store Read|
|Data Store Write|
|In Bus Element|
|Interpolation Using Prelookup|
|Out Bus Element|
To associate a block with a bus, in the Block Parameters dialog box, set
Data type to
name> and replace
name> with the bus object name.
If a subsystem that is in a library contains a block that uses a bus object, all instances of that block must match the bus object specification.
Do not set the minimum and maximum values for bus data on blocks with bus object data type. Simulink ignores these settings. Instead, set the minimum and maximum values for bus elements of the bus object specified as the data type. The values should be finite real double scalar.
For information on the
Maximum properties of a bus element, see
Using bus objects in a model involves performing these tasks, in many cases iteratively.
Determine where you need or want to use bus objects.
Determine how you want to manage the bus objects, to keep track of the bus objects used by a model and the models that use the bus objects.
Create the bus objects in the MATLAB base workspace.
Export the bus objects from the base workspace to a MATLAB code file or a MAT-file.
Import bus objects from files to models that use the bus objects.