Call Simulink Functions in Other Models Using Function Ports
Function ports allow a referenced model to call a Simulink® function defined in a second referenced model. A model can issue a function call through an invoking function port to invoke a function defined and exported in another model with an exporting function port block. You can use function ports to model client and server components in a distributed service architecture as well as to facilitate data sharing using a functional interface between component models.
A model that uses function ports must be an export-function model. See Export-Function Models Overview.
To create an exporting function port, add a Function Element block to your model, specify a name for the port, and specify one or more function elements.
For each function element, add a Simulink Function block to the model and
implement the desired algorithm inside the Simulink Function block. To connect
the Simulink Function block to the function port, set the Function
visibility parameter of the Trigger block inside the
Simulink Function block to port
, and enter the
port name in the Scope to port field.
Because the block is scoped to the port, it is not visible elsewhere within the model hierarchy and can be called only through the port. The block icon indicates the port scope.
To create an invoking function port, add a Function Element Call block to your model, specify a name for the port, and specify one or more function elements.
For each function element, add a Function-Call Subsystem block, and place a
Function Caller block inside the subsystem. To associate the Function
Caller block with the port, use dot notation:
PortName
.FunctionElementName
. The
block icon indicates the association with the port.
You can associate function ports with service interfaces authored in System Composer™ using the Function Element and Function Element Call blocks corresponding to the port.
When you reference a model with a function port, the port displays on Model block. To allow functions to be called through the ports, add a line between them. A ball icon appears at the end of the line next to the exporting function port. The attributes of the ports must match in number, names, and prototypes of function elements. Function ports can connect only to function ports and not to any other signal.
See Also
Simulink Function | Trigger | Function Caller | Function Element | Function Element Call
Related Topics
- Author Service Interfaces for Client-Server Communication (System Composer)
- Service-Oriented Sensor Modeling (System Composer)