Bus Creator
Group input signals or messages into bus
Libraries:
Simulink /
Commonly Used Blocks
Simulink /
Signal Routing
HDL Coder /
Signal Routing
Description
The Bus Creator block combines input signals or messages into a bus, which retains the separate identities of the signals and messages. By default, the Bus Creator block creates a virtual bus, which is analogous to a bundle of wires held together by tie wraps. Alternatively, the block can create a nonvirtual bus, which is analogous to a structure in C code.
Elements of a bus must have unique names. By default, each element of the bus inherits
the name of the element connected to the Bus Creator block. If duplicate
names are present, the Bus Creator block appends the port number to all
input element names. For elements that do not have names, the Bus Creator
block generates names in the form signaln
, where n
is the port number connected to the element. You can refer to elements by name when you
search for their sources or select elements for connection to other blocks. For element
naming guidelines, see Signal Names and Labels.
To extract elements from the bus by name, use a Bus Selector block.
To create a bus that contains other buses, connect the other buses to the Bus Creator block input ports.
Tip
For buses at subsystem and model interfaces, use Out Bus Element blocks instead of a Bus Creator block with an Outport block. Out Bus Element blocks:
Reduce line complexity and clutter in a block diagram.
Allow you to more easily change the interface incrementally.
Examples
Group Signal Lines Within Component
You can group signals into a virtual bus within a component by using Bus Creator blocks.
Open the model named VirtualBusCreation
, which contains three blocks.
To create a bus that contains the outputs from multiple blocks, click and drag to select the blocks. For this example, select the Chirp Signal and Sine Wave blocks. In the action bar that appears, click Create Bus.
The software adds a Bus Creator block and connects the inputs to that block. The output of the Bus Creator block is a virtual bus.
To make identifying the elements of the bus easier, label the inputs to the Bus Creator block. Double-click the line between the Chirp Signal block and the Bus Creator block. Then, enter Chirp
. Double-click the line between the Sine Wave block and the Bus Creator block. Then, enter Sine
.
To create a second bus that contains the first bus and the output of the Step block, click and drag to select the Bus Creator and Step blocks. In the action bar that appears, click Create Bus. Since the Sine
and Chirp
signals are elements of the input bus, the software creates the same bus regardless of whether your selection includes the Sine Wave and Chirp Signal blocks.
The software adds another Bus Creator block and connects the inputs to that block. The output of the Bus Creator block is a virtual bus that contains a nested bus.
You can nest buses to any depth. If one of the inputs to a Bus Creator block is a bus, then its output is a bus hierarchy that contains at least one nested bus.
Label the inputs to the new Bus Creator block. Double-click the line between the Step block and the Bus Creator block. Then, enter Step
. Double-click the line between the Bus Creator blocks. Then, enter NestedBus
. Optionally, arrange the blocks to improve the readability of the model.
Connect the output of the second Bus Creator block to a Scope block and label the output TopBus
. To visually identify the buses, compile the model by clicking Update Model or Run on the Modeling tab of the Simulink Toolstrip. Compiling the model updates the line styles.
Create Nonvirtual Buses Within Component
You can use Bus Creator blocks to create nonvirtual buses within components.
Open and compile the model named BusHierarchy
, which uses Bus Creator blocks to create a hierarchy of virtual buses. To compile the model, on the Modeling tab of the Simulink® Toolstrip, click Update Model or Run. Compiling the model updates the line styles, which you can use to visually identify buses.
mdl = BusHierarchy;
open_system(mdl)
set_param(mdl,SimulationCommand="Update")
To create this model, see Group Signal Lines Within Component.
The virtual buses in this model are not defined by Simulink.Bus
objects. To change the output of the Bus Creator blocks to nonvirtual buses, you must have bus objects that match the bus hierarchy.
To create the bus objects that correspond to TopBus
and NestedBus
, use the Simulink.Bus.createObject
function. In the MATLAB® Command Window, enter this command.
Simulink.Bus.createObject("BusHierarchy","BusHierarchy/Bus Creator1");
This function creates the bus object that corresponds to the output bus of the specified block. If the output bus contains nested buses, the function also creates bus objects that correspond to the nested buses. In this example, the function creates two bus objects that are named after the corresponding buses, TopBus
and NestedBus
.
To view the bus objects, open the Type Editor. In the Simulink Toolstrip, on the Modeling tab, in the Design gallery, click Type Editor. To expand an external data source or bus, click the arrow next to its name.
Now that you have bus objects that correspond to the nonvirtual buses you want to create, create the nonvirtual buses. In the Simulink Editor, double-click the Bus Creator block named Bus Creator1
. In the Block Parameters dialog box, set Output data type to Bus: TopBus
, select the Output as nonvirtual bus check box, and click OK. TopBus
is now a nonvirtual bus, while NestedBus
remains a virtual bus. To identify the nonvirtual bus by line style, compile the model.
Double-click the block named Bus Creator
. In the Block Parameters dialog box, set Output data type to Bus: NestedBus
, select the Output as nonvirtual bus check box, and click OK. NestedBus
is now a nonvirtual bus. To update its line style, compile the model.
If you do not save the bus objects, then you must recreate the bus objects when you reopen the model. For information on how to save the bus objects, see Specify Bus Properties with Bus Objects.
Extended Examples
Simulink Bus Capabilities
Work with buses in components, simplify component interfaces, and streamline common bus workflows.
Ports
Input
Port_1 — Input element to include in bus
scalar | vector | matrix | array | bus
The input ports accept the elements to include in the bus. The number of input ports is driven by the Number of inputs parameter.
Each Bus Creator block supports these combinations of input elements:
Signals only
Signals and signal buses
Messages only
Messages and buses
Buses only
You can specify variable-size input signals with upper bounds smaller
than the upper bounds of the variable-size signals that the corresponding Bus
Creator block input ports can accept. To configure the upper bounds of
variable-size signals that Bus Creator block input ports accept, use a
Simulink.BusElement
object. For more information, see Simulink.BusElement
. Variable-size input signals must have the same
dimensionality as the variable-size signals that the corresponding Bus
Creator block input ports are configured to accept.
Data Types: single
| double
| half
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| string
| Boolean
| fixed point
| enumerated
| bus
Complex Number Support: Yes
Output
Port_1 — Output virtual or nonvirtual bus
bus
The output bus is composed of the input elements. The Output as nonvirtual bus parameter specifies whether the output bus is a virtual or nonvirtual bus. For information about the types of buses, see Composite Interface Guidelines.
Data Types: single
| double
| half
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| string
| Boolean
| fixed point
| enumerated
| bus
Complex Number Support: Yes
Parameters
To edit Bus Creator block parameters interactively, double-click the block.
Number of inputs — Number of input elements
2
(default) | integer
The number of input elements must be an integer greater than or equal to 2. Increasing the number of inputs adds empty input ports to the block. Before you simulate the model, make sure that an input element is connected to each input port.
When you modify the Number of inputs parameter, click Refresh to update the list of elements.
If all input ports are already connected, you can add an input port to the Bus Creator block by connecting another line to it.
Interactively adding a port updates the Number of inputs parameter and adds the new element to the list of elements in the bus.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
function.
Specify the number of inputs as an integer greater than or equal to 2 or as a comma-separated list of element names. When you specify the names of elements in the bus, the number of inputs matches the number of element names you specify.
Parameter: | Inputs |
Values: | '2' (default) | integer in quotes | comma-separated list of element names in quotes |
Data Types: | char | string |
Example: set_param(gcb,'Inputs','3')
Example: set_param(gcb,'Inputs','element1,element2,element3')
Elements in the bus — List of input elements
list of element names
The list of input elements includes all elements that enter the block, including the elements of nested buses. An arrow next to an element indicates that an input element is a bus. To display the contents of that bus, click the arrow.
To highlight the source of an element that enters the block, select the element in the list and click Find.
If you change an element name while the dialog box is open, click Refresh to update the name in the list.
To rearrange the elements in the output bus, use the Up and Down buttons. You can select multiple top-level adjacent elements in the Elements in the bus list to reorder or remove.
To add or remove input elements, click Add or Remove, respectively. Then, update the block icon by clicking Apply or OK. Before you simulate the model, make sure that an input element is connected to each input port.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
function.
Specify the elements in the bus as a comma-separated list of element names. When you specify the names of elements in the bus, the number of inputs matches the number of element names you specify.
Parameter: | Inputs |
Values: | '2' (default) | integer in quotes | comma-separated list of element names in quotes |
Data Types: | char | string |
Example: set_param(gcb,'Inputs','element1,element2,element3')
Filter by name — Search term for filtering displayed input elements
text
To filter the displayed input elements, enter a search term. The filter does a partial-string search. Do not enclose the search term in quotation marks.
To access the filtering options, click the Show filtering options button to the right of the Filter by name box.
Enable regular expression — Option to filter displayed input elements by regular expression
off
(default) | on
Select this parameter to filter the displayed input elements with either regular expressions or partial search strings. By default, you can filter the displayed input elements with only partial search strings.
Regular expressions let you filter based on whether the input elements match a pattern.
For example, enter t$
in the Filter by
name box to display all elements whose names end with a
lowercase t
(and their immediate parents). For more
information, see Regular Expressions.
Dependencies
To access this parameter, click the Show filtering options button to the right of the Filter by name box.
Show filtered results as a flat list — Option to display filtered results as flat list
off
(default) | on
Select this parameter to display filtered results as a flat list that uses dot notation to reflect the bus hierarchy. By default, the filtered results appear in a hierarchical tree.
Dependencies
To access this parameter, click the Show filtering options button to the right of the Filter by name box.
Output data type — Data type of output bus
'Inherit: auto'
(default) | 'Bus: <object name>'
| <data type expression>
Specify the data type of the output bus.
If you select Bus: <object name>
, replace
<object name>
with the name of a Simulink.Bus
object. The bus object must be accessible when you edit the
model.
To define a Simulink.Bus
object using the Type Editor,
click the Show data type assistant button
, set Mode to Bus
object
, and then click the Edit button.
If you select <data type expression>
,
specify an expression that evaluates to a Simulink.Bus
object.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
function.
Parameter: | OutDataTypeStr |
Values: | 'Inherit: auto' (default) | 'Bus: <object name>' |
Example: set_param(gcb,'OutDataTypeStr','Bus:
control')
Require names of inputs to match names above — Option to check that input element names match names listed in dialog box
off
(default) | on
This parameter might be removed in a future release. To enforce strong data typing, use the Use names from inputs instead of from bus object parameter.
When selected, this parameter checks that the input element names match the names listed in the Block Parameters dialog box. If the element names do not match, the software returns an error.
Dependencies
This parameter is ignored if you select Use names from inputs instead of from bus object.
This parameter reverts to
off
if you programmatically change Number of inputs.
Rename selected signal — New name for selected input element
''
(default) | character vector
Specify a new name for the selected input element. See Signal Names and Labels for name guidelines.
Dependencies
To enable this parameter, select Require names of inputs to match names above.
Use names from inputs instead of from bus object — Option to use names from input elements instead of from bus object
on
(default) | off
By default, the Bus Creator block uses the input element names as the
output bus element names, even when you specify a Simulink.Bus
object
as the data type.
To inherit bus element names from the bus object, clear this parameter. Clearing the parameter:
Enforces strong data typing.
Avoids having to enter an element name multiple times: in the bus object and in the model. Entering the name multiple times can create accidental element name mismatches.
Supports the array of buses requirement to have consistent element names across array elements.
To enforce strong data typing with this parameter selected, set the Element name mismatch configuration parameter to
error
. This configuration parameter checks that input
element names match the corresponding names in the bus object.
Dependencies
To enable this parameter, set Output data
type to a Simulink.Bus
object.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
function.
Parameter: | InheritFromInputs |
Values: | 'on' (default) | 'off' |
Example: set_param(gcb,'InheritFromInputs','off')
Output as nonvirtual bus — Option to output nonvirtual bus
off
(default) | on
Select this parameter to output a nonvirtual bus instead of a virtual bus.
All elements in a nonvirtual bus must have the same sample time, even if the elements of
the associated Simulink.Bus
object specify inherited sample times for
some elements. Any operation resulting in a nonvirtual bus containing elements with
different sample rates generates an error. To change the sample time of an element or
bus that has a different sample time than the other nonvirtual bus input elements, use a
Rate Transition block. For details, see
Modify Sample Times for Nonvirtual Buses.
To generate code that uses a C structure to define the structure of the bus that this block creates, select this parameter.
Dependencies
To enable this parameter, set Output data
type to a Simulink.Bus
object.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
function.
Parameter: | NonVirtualBus |
Values: | 'off' (default) | 'on' |
Example: set_param(gcb,'NonVirtualBus','on')
Block Characteristics
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Actual data type or capability support depends on block implementation.
HDL Code Generation
Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.
HDL Coder™ provides additional configuration options that affect HDL implementation and synthesized logic.
To learn more about using buses for HDL code generation, see Buses (HDL Coder) and Use Buses to Improve Readability of Model and Generate HDL Code (HDL Coder).
This block has one default HDL architecture.
ConstrainedOutputPipeline | Number of registers to place at
the outputs by moving existing delays within your design. Distributed
pipelining does not redistribute these registers. The default is
|
InputPipeline | Number of input pipeline stages
to insert in the generated code. Distributed pipelining and constrained
output pipelining can move these registers. The default is
|
OutputPipeline | Number of output pipeline stages
to insert in the generated code. Distributed pipelining and constrained
output pipelining can move these registers. The default is
|
This block supports these data types for HDL code generation:
Input Port | Dimension | Fixed-Point | Floating-Point | Built-in Integers | Boolean | Complex Signal |
---|---|---|---|---|---|---|
Port_1 | Scalar Vector Matrix | Yes | Half Single Double | Yes | Yes | Yes |
PLC Code Generation
Generate Structured Text code using Simulink® PLC Coder™.
Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.
Actual data type or capability support depends on block implementation.
Version History
Introduced before R2006aR2023a: Variable-size input signal upper bound can be smaller than upper bound of variable-size signal that the corresponding Bus Creator block input port can accept
Starting in R2023a, the Bus Creator block supports variable-size input signals with upper bounds smaller than upper bounds of variable-size signals that the corresponding Bus Creator block input ports can accept.
This enhancement allows you to use variable-size input signals when the upper bounds of input signals are not equal to the upper bounds of variable-size signals that the corresponding Bus Creator block input ports can accept.
R2014b: Require names of inputs to match names above parameter is not recommended
The Require names of inputs to match names above parameter might be removed in a future release. To enforce strong data typing, use the Use names from inputs instead of from bus object parameter instead.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)