To ensure correct harnessing of bus ports of Simulink models, these guidelines must be followed. Note that best practices state that:

1.When harnessing a top level model (the Simulink S-Function is placed at the top level model and connected to the input and output ports of the model), or wrapping a subsystem that is a model (The S-Function is placed outside of a model block that is being wrapped via the Transform’s Subsystem to wrap property). Note that when wrapping a model reference, the model reference is required to expose inputs and outputs as a bus data type, or an error will occur.

a.Bus types must be defined through the Simulink Bus Editor with the bus definitions directed to be loaded (through a PreLoadFn callback, a workspace load directive, or via the S-Function Transform property Script File Path).

b.Each input and output port should have their data type definition set to be the appropriate bus type:


c.For input ports, as long as the bus type is defined, it is irrelevant whether or not the “Output as nonvirtual bus” option is checked; the S-Function transform will always output as a nonvirtual bus type. Input ports should ALWAYS define a bus type in order for signals to propagate properly and for modeling errors to be detected.

d.For output ports:

(1)If the bus type is defined as the data type, the port can be fed either a virtual or nonvirtual bus. This definition will be maintained until the input port of the S-Function block where it will be converted internally to a nonvirtual bus. 

(2)If the bus type is NOT defined the following behaviors will occur, AND this is top level model wrap:

(i)If a virtual bus feeds the output port block, all of the signals in the bus must be of the same data type. Simulink will convert this to an vector of this data type for the number of signals in the bus. Virtual buses that are of differing data types will cause an error during compilation and will not be able to be harnessed.

(ii)If a nonvirtual bus feeds the output port block, the bus type will be propagated to the transform properly.

2.When wrapping a Subsystem block, the following requirements must be met. If the requirements are not met, you will see port dimension mismatch errors, data type mismatch (e.g. virtual bus signals must have the same data type), or bus signals being harnessed as arrays.

a.Any bus signals that enter the Subsystem block must be nonvirtual bus signals. It is not enough that the input port defines its data type as a bus signal type; the input to the subsystem is required to be nonvirtual. This ensures that data type propagation occurs correctly.

b.Any output ports that are bus ports must have inputs that are nonvirtual bus signals. The output port may inherit or explicitly define the bus type.

In summary:

Ensure that bus signals are defined for buses in the model.

Ensure that the bus signals are loaded into the workspace prior to the model loading. This can be done through a load callback, a workspace initialization, or through the S-Function Transform Script file path setting.

When wrapping a subsystem using the S-Function transform, all bus inputs and outputs to and from the subsystem must be nonvirtual bus signals. If this is not the case, errors will occur during harnessing.

When harnessing a model at the top level, ensure that all ports that are input or output signals that define buses have their data types explicitly set to the bus signal type. During harness, inputs to the model from MxVDev will always be converted to nonvirtual buses, and any virtual buses that are defined will remain virtual except for at entry into the S-Function block.



Related Topics:

S-Function Connector to Simulink

Simulink Bus Demo sample project