quarc_blocking_server_script_demo.m
quarc_basic_client_demo.mdl
Open these M-files

QUARC Blocking Server Script Demo

This example consists of two files; a client model and a server script. It demonstrates how to use the QUARC Stream MATLAB functions to establish a connection between a MATLAB script (server) and a Simulink model (client). The script uses blocking I/O as the mode of operation to send/receive data to/from the client model. For a detailed description of the client model and how it operates, please refer to the Basic Communications section of the QUARC documentation. You can also refer to the QUARC Basic Communications Demo for more information.

System Requirements

In this demonstration, the client model is run using QUARC for Windows target, but you can run it in normal simulation and on other targets supported by QUARC. However, the server script must be run in another instance of MATLAB.

To run on other QUARC targets, the hostname in the URI specified in the Stream Client block will need to be changed to reflect the machine running the server script. Further details may be found below under the heading Running the example on a different target.

Configuring the Demonstration

To open the example files, click on the "Open these M-files" link found on the top right corner of this page. Unlike most demonstrations, this link will actually spawn a separate instance of MATLAB in which to run the server script while opening the QUARC Basic Client Demo Simulink model in the current instance of MATLAB.

To set up the demonstration, double-click on the Stream Client block in the quarc_basic_client_demo.mdl model and make sure the URI of host to which to connect parameter of the Stream Client block is the same as the uri variable in the quarc_blocking_server_script_demo.m MATLAB script (with the exception of the hostname, if the client and server are run on separate machines).

Demonstration

Building, deploying and starting the model

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

Running the model

Double-click on the "Received Data - Client" Scope block in the model to open the Scope.

Next, in the MATLAB Editor in which the server script is opened, run the script by pressing F5 or pressing the Run button.

A sawtooth waveform of amplitude 4 will appear in the "Received Data - Client" Scope. Meanwhile, all the values being sent by the client model to the server script are printed out on the MATLAB command window. The client model sends a sawtooth wave to the server while the server script sends a different sawtooth to the client model.

Scope with Sawtooth Wave of Amplitude 4

The server script will attempt to accept new connections once the existing connection is closed from the client side. To see this, stop the client model by clicking on the Stop button. Next, restart the model and you will notice that the connection gets re-established and sending/receiving operation resumes.

Stopping the script and model

Press the Esc key to stop the script.

Once the client script is stopped, refer to One Step Process in QUARC Basic Procedures to stop the 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.

Be sure to change hostname of the URI in the Stream Client block to match the hostname of the machine running the server script.