quarc_blocking_client_script_demo.m
quarc_basic_server_demo.mdl
Open these M-files

MATLAB Command Line

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

system(['"', fullfile(matlabroot, 'bin', 'matlab.exe'), '" -r "edit quarc_blocking_client_script_demo.m"']); quarc_basic_server_demo

QUARC Blocking Client Script Demo

This example consists of two files; a server model and a client script. It demonstrates how to use the QUARC Stream MATLAB functions to establish a connection between a MATLAB script (client) and a Simulink model (server). The script uses blocking I/O as the mode of operation for sending/receiving data to/from the server model. For a detailed description of the server 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 server model is run using the QUARC for Windows target, but you can run it in normal simulation and on other targets supported by QUARC. However, the client script must be run in another instance of MATLAB.

To run on other QUARC targets, the hostname in the URI specified in the script block will need to be changed to reflect the machine running the client 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 client script while opening the QUARC Basic Server Demo Simulink model in the current instance of MATLAB.

To set up the demonstration, double-click on the Stream Server block in the quarc_basic_server_demo.mdl model and make sure the URI upon which to listen parameter of Stream Server block is the same as the uri variable in the quarc_blocking_client_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 - Server" Scope block in the model to open the Scope.

Next, in the MATLAB Editor in which the client 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 - Server" Scope. Meanwhile, all the values being sent by the server model to the client script are printed out on the MATLAB command window. The server model sends a sine wave to the client script while the client sends a sawtooth wave to the server model.

Scope with Sine Wave of Amplitude 2

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 script to match the hostname of the machine running the QUARC Basic Server Demo model.