Welcome.
Hi.
I'm Kevin, and I'm a software developer here at MathWorks.
I'm here today to demonstrate authoring
client-server interfaces in System Composer.
For this demonstration, we'll be first covering
the basics of how to author client-server interfaces.
Then we'll walk through an example
that models a controller requesting services
from two sensors.
To begin, let's first create a software architecture model.
To create a software architecture model,
click Software Architecture Model on the Simulink
start page.
Client-server communications in System Composer
are modeled through client ports and server ports.
To create a client or server port,
let's first create a software component for the controller
by dragging a software component from the tool strip.
Then let's create a component for the sensor.
Click on the border of the component
and select the Client or Server option from the dynamic menu.
Let's create a client port for the controller.
Now let's create a server port for the sensor.
To create a client-server connection
modeling a call to a service from the client port
to the server port, drag a connection.
Let's rename the port SensorData.
You can specify an interface for the client-server connection
through the Interface Editor.
Go to the Modeling tab and select Interface Editor.
To specify an interface, you can go to the Add interface button
and select Service Interface from the dropdown menu.
To specify the services provided by the sensor component,
you can create function elements.
To create a function element, select the Service Interface
and click the Add Element button.
You can further specify the function element
by changing the prototype of the function.
You can change the name of the function
by editing the prototype of the function element
in the Interface Editor.
Similarly, you can change the number
of arguments in the Function element
by editing the prototype.
To associate a service interface with a client-server
connection, click either the client or server port
and open the Property Inspector.
To open the Property Inspector, go to the Modeling tab
from the Design section and select Property Inspector.
Expand the Interface section and select the service interface
from the Name dropdown menu to assign the interface.
The service interface is now associated with the port.
If you click the other port, you can
see that the service interface has also
been associated with it.
To begin implementing a client-server relationship
between two components, you can create Simulink behaviors
from the components.
Right-click the component with the client port
and select Create Simulink Behavior.
From the menu, click OK.
As you can see, a Simulink behavior
was created for the component.
You can do the same for the sensor
component with the server port.
Going into the component with a server port,
we can see that a Simulink function has been automatically
created for each service specified in the service
interface.
You can go on to implement the service in Simulink.
Similarly, you can see that a function calls up
system has been created in the client component
for each service, as well.
Now that you know the basics of how to specify services
for components with client-server ports,
let's now go into the full example
to see how you can schedule services,
implement them, and generate code for them.
This model contains a controller component and two sensor
components, representing two temperature sensors
in a building.
We can observe that the controller component
has a client relationship with the sensor components.
This means that the controller will
call the services implemented by the sensor component
and specified by the service interface.
The service interface sensor command
has two services-- fetchData and reset.
Both services are provided by the sensor component
and called by the controller component.
You can schedule the services in the service interface
through the Functions Editor.
Go to the Modeling tab and select Functions Editor.
You can change the order of the functions
by clicking the Increase Execution Order and Decrease
Execution Order button.
You can also use the Functions Editor
to specify the period between calls to the same service.
Once you have specified the order of the services,
let's simulate in order to observe
the sequence of service calls.
Once the simulation finishes, open the Sequence Viewer.
To open the sequence viewer, select the Simulation tab,
go to the review results section,
and select Sequence Viewer.
As you can see, the sequence viewer
captures the service calls made from the controller
to the sensors during simulation.
If you want to see the unique types of service interfaces
and components, you can use the Class Diagram view.
To open the Class Diagram view, go to the Modeling tab.
Select Architecture Views in the View section.
Create a new view.
Click Select All Components from the Add Component Filter
dropdown, click Apply, and select the Class Diagram view
from the Diagram section.
The types and relationships between components
are displayed in the new view.
To generate code from this model,
open the Code perspective and click the Generate Code button.
Now that code is generated, let's dive into the sensor
model and see how code for the service interface
has been generated and used.
For the service interface an abstract class
has been generated containing the services.
These services are implemented by the sensor model
and called by the controller model.
Now you have learned how to alter client-server interfaces
and how to simulate client-server interfaces
in System Composer.
Don't forget to consult the MATLAB help documentation
for more resources with functions and examples
regarding client-server interfaces.