Main Content

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.

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.

System Composer canvas with two software components. One component is named Sensor and has a client port. The other component is named RTE and has a server port. The ports are connected to each other.

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.

Interface Editor with a service interface definition displayed. The service interface has 2 function elements, with function signatures "y = f0(u)" and "y = f1(u)".

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.

Interface Editor with a service interface definition displayed. The service interface has a function elements with function signature "[y1,y2] = f0(u1,u2)".

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: Type, Dimensions, Units, Complexity, Minimum, Maximum, and Description.

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 Create Simulink 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 Component block.

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.

Simulink canvas with two port-scoped Simulink Function blocks and two Function Element blocks.

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

For a component with a client port, the model contains a Function Element Call block and a Function-Call Subsystem block.

Simulink canvas with two Function Element Call blocks and two Function-Call Subsystem blocks.

The Function-Call Subsystem block contains a Function Caller block for each function element of the service interface associated with the client port.

Inside each function-call subsystem there is a Function Caller block.

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

You can model asynchronous execution if you select the Asynchronous check box in the Interface Editor or the Property Inspector for your function element.

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.

The message output port that corresponds to the Function Caller block is connected to a Message Triggered Subsystem block that processes messages.

Asynchronous client-server interfaces in Simulink.

See Also

Blocks

Functions

Related Topics