Inspect Generated Code for Nonvirtual Buses
This example shows how nonvirtual buses appear in the generated code for a model.
Open and simulate the example model, which contains a nonvirtual bus.
mdl = "NonvirtualBusCode";
open_system(mdl)
sim(mdl);
To generate code for the model, in the Simulink Toolstrip, on the Apps tab, in the Apps gallery, click Simulink Coder. On the C Code tab that opens, click Generate Code. Alternatively, press Ctrl+B or enter this command.
slbuild(mdl)
### Searching for referenced models in model 'NonvirtualBusCode'. ### Total of 1 models to build. ### Starting build procedure for: NonvirtualBusCode ### Successful completion of code generation for: NonvirtualBusCode Build Summary Top model targets: Model Build Reason Status Build Duration ======================================================================================================= NonvirtualBusCode Information cache folder or artifacts were missing. Code generated. 0h 0m 14.11s 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 15.056s
To see the generated files, open the NonvirtualBusCodeGenModel_grt_rtw
folder.
NonvirtualBusCode_types.h
defines the Simulink.Bus
object as a structure.
typedef struct { real_T a; real_T b; real_T c; } BusObject;
NonvirtualBusCode.h
defines the Unit Delay block using the BusObject
struct.
typedef struct { BusObject UnitDelay_DSTATE; /* '<Root>/Unit Delay' */ } DW_NonvirtualBusCode_T;
NonvirtualBusCode.c
implements the Unit Delay block, which passes the nonvirtual bus to the Outport block.
NonvirtualBusCode_Y.Out1 = NonvirtualBusCode_DW.UnitDelay_DSTATE;