Model Client-Server Communication Using Function Ports
You can model service-oriented communication in Simulink® using export-function models and function ports. Function ports allow you to facilitate data sharing between component models. This topic shows you how to use function ports to model client and server components in Simulink.
To start from Simulink, client or server component models that use function ports must be an export-function model. If a model uses synchronous functions, the parent model of the components must also be an export-function model. For the configuration, see Export-Function Models Overview.
If you want to model service-oriented communication at the architecture level, you can use preconfigured Simulink export-function models for components in System Composer™ software architectures. For more information, see Service Interfaces Overview (System Composer).
Model Server Component with Function Element Block
A server component is one that provides services. Services are modeled as Simulink Function blocks that are scoped to Function Element ports. For each server port in your service interface, there is a Simulink Function block where you can implement the desired algorithm. The Function Element block is a function port with the function elements specified in your service interface.
To modify the port name or function elements, open the properties of the Function Element block.
Inside the Simulink Function block, there is a Trigger block. To associate the Simulink function with the server port:
Set the Function visibility parameter of the Trigger block inside the Simulink Function block to
port
.Set the Scope to port parameter of the Trigger block to the port name.
The Simulink Function block is scoped to the server port, meaning that the port is not visible elsewhere in the model hierarchy and you can only call the function through the server port. The dot notation near the Function Element block shows the association of the function with the port. The port name is first, followed by the function name.
To implement function behavior, double-click the Simulink Function block. Inside the Simulink Function block is a Trigger block, an ArgIn block, and an ArgOut block. Add any necessary blocks to the function subsystem and connect elements to the ArgIn block and the ArgOut block.
Model Client that Requires Services
A client model is one that requires services from other models. A required service is modeled using a Function Caller block and a Function Element Call block.
To modify the port name or function elements, open the properties of the Function Element Call block.
The Function Element Call block is connected to the Function-Call Subsystem block because the you call the function through the function port.
Inside the Function-Call Subsystem block is a Function Caller block. To associate the function caller with the client port, set the Function prototype parameter of the Function Caller block to use dot notation with the port name followed by the function name.
The dot notation near the Function Element Call block shows the association of the function with the port. The port name is first, followed by the function name. The Inport block is connected to the Function-Call Subsystem block with a root-level input port connection.
To implement the function call inside the Function-Call Subsystem block, double-click the Function-Call Subsystem block. Add any necessary blocks to the function call subsystem to represent an input and an output.
Configure Asynchronous Execution with Function Ports
Asynchronous execution is when the client sends a request to the server, the function executes asynchronously based on the priority order, and the function returns the output arguments to the client.
The function executes based on the ordering you define in the Schedule Editor. The behavior of the message payload can change depending on the number of function output arguments.
If the function has one output argument, the output argument becomes the message payload.
If the function has more than one output argument, the Function Caller block bundles the output arguments as a structure that becomes the message payload.
For the server model, the Trigger block parameters are different than those of a synchronous system. To associate the Simulink function with the server port:
Set the Trigger type parameter of the Trigger block to
function-call
.Set the Treat as a Simulink Function parameter of the Trigger block to
on
.Set the Function visibility parameter of the Trigger block to
port
.Set the Execute function call asynchronously parameter of the Trigger block to
on
.
For the client model, to associate the function caller with the client port, set the
Execute function call asynchronously parameter of the
Function Caller block to on
. The
Message
Triggered Subsystem block acts as a callback for the function. You must
connect the Message Triggered Subsystem block to the message output
port of the Function Call Subsystem block.
For more information, see Simulate Asynchronous Services for Vehicle Headlight Management (System Composer).
See Also
Simulink Function | Trigger | Function Caller | Function Element | Function Element Call | Function-Call Subsystem | Model | Message Triggered Subsystem
Related Topics
- Export-Function Models Overview
- Define Port Interfaces Between Components (System Composer)
- Software Component Modeling
- Service Interfaces Overview (System Composer)
- Model Service-Oriented Communication Between Sensors (System Composer)
- Simulate Asynchronous Services for Vehicle Headlight Management (System Composer)