Author Service Interfaces for Client-Server Communication
You can model client-server connections between software components in software architectures in System Composer™ using client ports and server ports and associating service interfaces with these ports. This topic shows a workflow for modeling client-server communication starting from a System Composer software architecture and implementing client-server behavior with Simulink.
To expose services performed by a software component, create a server port on that component. To access those services from within another software component, create a client port on the second component and connect the two ports. The ball and socket icons represent server and client ports, respectively. You can also author client and server ports at the composition level, with client-server lines crossing multiple hierarchies.
A service interface defines the functional interface between client and server components. Each service interface consists of one or more function elements.
A function element describes the attributes of a function in a client-server interface.
Use the Interface Editor to author and edit service interfaces.
Edit the function prototype on a function element to change the number and names of inputs and outputs of the function. Edit function element properties as you would edit other interface element properties. Function argument types can include built-in types as well as bus objects. You can specify function elements to support:
Synchronous execution — When the client calls the server, the function runs immediately and returns the output arguments to the client.
Asynchronous execution — When the client makes a request to call the server, the function is executed asynchronously based on the priority order defined in the Functions Editor and Schedule Editor and returns the output arguments to the client.
For asynchronous simulation, for the function element on the Interface Editor, select the Asynchronous check box. If a function element is selected in the Interface Editor, you can also specify the function element as asynchronous in the Property Inspector.
A function argument describes the attributes of an input or output argument in a function element.
You can set the properties of a function argument in the Interface Editor just as you would any value type:
Once you have defined a service interface in the Interface Editor, you can assign it to client and server ports using the Property Inspector. You can also use the Property Inspector to assign stereotypes to service interfaces.
To implement function behavior for components with client or server ports using
referenced Simulink® models, right-click a component and select
behavior, or use the
createSimulinkBehavior function. System Composer creates a new export-function model and links the component to the new
model. The component is now a Reference
For a component with a server port, the model contains a Function Element block and a port-scoped Simulink Function block for each function element of the service interface associated with the server port. The Simulink Function blocks are preconfigured with a function interface specification to match each function element of the service interface. The Function Element block creates an exporting function port on the corresponding Reference Component block. The attributes of the port are based on the service interface definition.
To implement the desired algorithm for each server function, open the Simulink Function blocks. Then, add and connect the needed blocks and other modeling elements.
Synchronous Client-Server Simulink Behavior
The Function Caller blocks are preconfigured with a Function prototype parameter value and argument specifications to match each function element of the service interface. The Function Element Call block creates an invoking function port on the corresponding Reference Component block. The attributes of the port are based on the service interface definition.
Asynchronous Client-Server Simulink Behavior
The export-function model for the Simulink behavior for the client model now has a Function Caller block with a message output port consistent with the number of output arguments for the Simulink Function block.
If there is one function output argument, the output argument becomes the message payload.
If there is more than one function output argument, the Function Caller block bundles the output arguments as a structure that becomes the message payload.
- Function Element | Function Element Call | Simulink Function | Function Caller | Function-Call Subsystem | Message Triggered Subsystem | Reference Component