Change Values of Signals Using C Function Block and Buses
This example shows how to use buses with a C Function block. In this example, two Constant blocks supply values to a Bus Creator block, which combines signals and sends the bus signal to a C Function block. Code in the C Function block changes the values of the signal elements in the bus. The output bus signal then pass through a Bus Selector block, and the output values are displayed separately in two Display blocks.
open_system('mCFunction_BusWithoutCStruct')
Output Code Specification
The C Function Block Parameters dialog box contains the output code and parameters that determine the output signal values. To open the Block Parameters dialog box, double-click the block. On the Simulation tab of the dialog box, under Output, you can view and change output parameters.
Signal Data Specification
The Ports and Parameters table in the C Function Block Parameters dialog box contains the signal data specifications. To use a Simulink® bus for both the input and output signals, the Type value for both the signals is set to Bus: SimpleBus
. The bus is defined in the SimpleBus.mat
file and loaded into the model using model callback parameter PreLoadFcn
.