quarc_intermediate_server_variable_demo.mdl
quarc_intermediate_client_variable_demo.mdl
Open these models

MATLAB Command Line

Click to copy the following command line to the clipboard. Then paste it in the MATLAB Command Window:

quarc_intermediate_server_variable_demo; quarc_intermediate_client_variable_demo

QUARC Intermediate Communications Variable-Size Signals Demo

This example consists of two Simulink models; a server and a client. It demonstrates how to use the Intermediate Communications blockset from the QUARC Targets Library to establish a connection between two Simulink models and to pass variable-size signals between the client and server using only a single Stream Read and Stream Write block. For a detailed description of these models and how they operate, please refer to the Intermediate Communications section of the QUARC documentation.

Intermediate Server Variable-Size Signals Demo Simulink Diagram

Intermediate Client Variable-Size Signals Demo Simulink Diagram

Configuring the Demonstration

To set up the demonstration, double-click on the Stream Answer block in the quarc_intermediate_server_variable_demo.mdl model and on the Stream Call block in the quarc_intermediate_client_variable_demo.mdl model and make sure the URI upon which to listen parameter of Stream Answer block is the same as the URI of host to which to connect parameter of the Stream Call block.

Demonstration

Building, deploying and starting the models

Refer to One Step Process in QUARC Basic Procedures to build, deploy and start each model.

Note that the order in which you start the models is not important. However, in practical situations, the server side should always be running before the client starts.

Warning In the case of using UDP as the communication protocol, it's necessary to start the server prior to the client. The reason is UDP does not establish a connection between client and server, and server relies on the IP address of its received packages to communicate. When the client is started, it sends a data package to the server, and because of its blocking design, it waits for a reply from the server which has not been started yet. In the other hand, when the server is started, it waits for a package from the client to know the IP address of the client. Therefore, both parties wait for each other, and no data is communicated.

This problem can be solved when the client is running on Windows. The solution is to add unreachable=yes in front of the client URI. In this case, when server is unreachable an error signal is created internally, and the client tries to send the starting data package again. Therefore, when the server is started, it eventually receives a data package from the client making it leave its listening state, and start the communication.

Running the model

Double-click on the "Plot Received Data" subsystem in the quarc_intermediate_server_variable_demo.mdl model. The data received from the client will be shown in the "Data received from client" Display block. Double-click on the "Plot Received Data" subsystem in the quarc_intermediate_client_variable_demo.mdl model to see the data received from the server in the "Data received from server" Display block. Double-click on the "Received Data - Client" Scope to plot the signal on a Scope as well.

The "Data received from client" Display will show the two-dimensional matrix data received from the client. The dimensions of the data displayed will constantly change in a repeating pattern as the client modulates the dimensions of the signal it sends to the server. Each element in the matrix is a sine wave of amplitude 0.49. Each sine wave is biased by the number of the element in the matrix (incrementing row-by-row).

Meanwhile, the "Data received from server" Display will show a vector of data received from the server. In this case, the number of elements in the vector changes in a repeating pattern as the server modulates the length of the vector that it sends to the client. Each element in the vector is a sine wave of amplitude 0.49. Each sine wave is biased by the element number. The data is also shown on the "Received Data - Client" Scope. In this case, traces are only plotted when the dimensions of the vector include data for that trace. Hence, there are gaps in the traces corresponding to when that particular element is not included in the variable-size vector signal received from the server.

Display with variable-size matrix of sine waves of amplitude 0.49

Display with variable-size vector of sine waves of amplitude 0.49

Scope with variable-size vector of sine waves of amplitude 0.49

Stopping the models

Refer to One Step Process in QUARC Basic Procedures to stop each model.

Running the example on a different target

To run the example on a different target, refer to the instructions on the Running QUARC Examples on Remote Targets page.

If the quarc_intermediate_server_variable_demo.mdl and the quarc_intermediate_client_variable_demo.mdl model are being run on different targets, then the URI of the Stream Call block in the client model should use the host name or IP address of the machine running the server for the hostname of its URI. For example, if the server is running on a machine with IP address 192.168.0.16 and the URI of the Stream Answer block in the server model is tcpip://localhost:18000, then the URI of the Stream Call block in the client model should be tcpip://192.168.0.16:18000.