Buses in Generated Code

If you have a Simulink® Coder™ license, the various techniques for defining buses are essentially equivalent for simulation, but the techniques used can make a significant difference in the efficiency, size, and readability of generated code. For example, a nonvirtual bus appears as a structure in generated code, and only one copy exists of any algorithm that uses the bus. The use of a structure in the generated code can be helpful when tracing the correspondence between the model and the code. For example, below is the generated code for Bus Creator block in the ex_bus_logging model.

A virtual bus does not appear as a structure or any other coherent unit in generated code, and a separate copy of any algorithm that manipulates the bus exists for each element.

Using buses properly results in efficient code and visually clean models. If you intend to generate production code for a model that uses buses, see Code Generation with Buses for information about the best techniques to use.

Was this topic helpful?