Documentation

Simulink Real-Time Interface Blocks to Simulink Models

Simulink User Interface Model

A user interface model is a Simulink® model containing Simulink blocks from add-on products and interface blocks from the Simulink Real-Time™ block library. This user interface model can connect to a custom graphical interface using Simulink 3D Animation™ or Altia® products. The user interface model runs on the development computer and communicates with your real-time application running on the target computer using To Target and From Target blocks.

The user interface allows you to change parameters by downloading them to the target computer, and to visualize signals by uploading data to the development computer.

Simulink 3D Animation — The Simulink 3D Animation product enables you to display a Simulink user interface model in 3-D. It provides Simulink blocks that communicate with Simulink Real-Time interface blocks. These blocks then communicate to a graphical interface. This graphical interface is a Virtual Reality Modeling Language (VRML) world displayed with a web browser using a VRML plug-in.

Altia Design — Altia also provides Simulink blocks that communicate with Simulink Real-Time interface blocks. These blocks then communicate with Altia's graphical interface or with a web browser using the Altia ProtoPlay plug-in.

Creating a Custom Graphical Interface

The Simulink Real-Time block library provides Simulink interface blocks to connect graphical interface elements to your real-time application. The steps for creating your own custom user interface are listed below:

  1. In the Simulink real-time application model, decide which block parameters and block signals you want to have access to through graphical interface control devices and graphical interface display devices.

  2. Tag the block parameters in the Simulink model that you want to be connected to a control device. See Marking Block Parameters.

  3. Tag the signals in Simulink model that you want to be connected to a display device. See Marking Block Signals.

  4. In the MATLAB® interface, run the function SimulinkRealTime.utils.createInstrumentationModel to create the user interface template model. This function generates a new Simulink model containing only the Simulink Real-Time interface blocks (To Target and From Target) defined by the tagged block parameters and block signals in the real-time application model.

  5. To the user interface template model, add Simulink interface blocks from add-on products (Simulink 3D Animation, Altia Design).

    • You can connect Altia blocks to the Simulink Real-Time To PC Target interface blocks. To Target blocks on the left should be connected to control devices.

    • You can connect Altia and Simulink 3D Animation blocks to the Simulink Real-Time From Target interface blocks. From Target blocks on the right should be connected to the display devices.

    You can position these blocks to your liking.

  6. Start both the real-time application and the Simulink user interface model that represents the application.

To Target Block

This block behaves as a sink and usually receives its input data from a control device. The purpose of this block is to write a new value to a specific parameter in the real-time application.

This block is implemented as a MATLAB S-function. The block is optimized so that it only changes a parameter on the real-time application when the input value differs from the value that existed at the last time step. This block uses the parameter downloading feature of the Simulink Real-Time command-line interface. This block is available from the slrtlib/Displays and Logging block sublibrary. See To Target for further configuration details.

    Note:   The use of To Target blocks requires a connection between the development and target computers. Operations such as opening a model that contains these blocks or copying these blocks within or between models will take significantly longer than normal without a connection between the development and target computers.

From Target Block

This block behaves like a source and its output is usually connected to the input of a display device.

Because only one numerical value per signal is uploaded during a time step, the number of samples of a scope object is set to 1. The block uses the capability of the Simulink Real-Time command-line interface and is implemented as a MATLAB S-function. This block is available from the slrtlib/Displays and Logging sublibrary. See From Target for further configuration details.

    Note:   The use of From Target blocks requires a connection between the development and target computers. Operations such as opening a model that contains these blocks or copying these blocks within or between models will take significantly longer than normal without a connection between the development and target computers.

Creating a Real-Time Application Model

A real-time application model is a Simulink model that describes your physical system, a controller, and its behavior. You use this model to create a real-time application, and you use this model to select the parameters and signals you want to connect to a custom graphical interface.

Creating a real-time application model is the first step you need to do before you can tag block parameters and block signals for creating a custom graphical interface.

See Marking Block Parameters and Marking Block Signals for descriptions of how to mark block properties and block signals.

Marking Block Parameters

Tagging parameters in your Simulink model allows the function SimulinkRealTime.utils.createInstrumentationModel to create To Target interface blocks. These interface blocks contain the parameters you connect to control devices in your user interface model.

After you create a Simulink model, you can mark the block parameters. This procedure uses the model xpctank as an example.

    Tip   The xpctank model blocks and signals may contain placeholder tags illustrating the syntax. As you create your own copy of the model using these procedures, replace these tags with your new tags or add the new tags using the multiple label syntax.

  1. Open a Simulink model. For example, in the MATLAB Command Window, type

    xpctank
  2. Point to a Simulink block, and then right-click.

  3. From the menu, click Properties.

    A Block Properties dialog box opens.

  4. In the Description box, delete the existing tag and enter a tag to the parameters for this block.

    For example, the SetPoint block is a constant with a single parameter that selects the level of water in the tank. Enter the tag:

    xPCTag(1)=water_level;

    The tag has the following syntax

    xPCTag(1, . . . index_n)= label_1 . . . label_n;

    For single dimension ports, the following syntax is also valid:

    xPCTag=label;

    index_n -- Index of a block parameter. Begin numbering parameters with an index of 1.

    label_n -- Name for a block parameter that will be connected to a To Target block in the user interface model. Separate the labels with a space, not a comma.

    label_1...label_n must consist of the same identifiers as those used by C/C++ to name functions, variables, and so forth. Do not use names like -foo.

  5. Repeat steps 1 through 3 for the remaining parameters you want to tag.

    For example, for the Controller block, enter the tag:

    xPCTag(1,2,3)=upper_water_level lower_water_level
         pump_flowrate;

    For the PumpSwitch and ValveSwitch blocks, enter the following tags respectively:

    xPCTag(2)=pump_switch;
    xPCTag(1)=drain_valve;

    To create the To Target blocks in an user interface model for a block with four properties, use the following syntax:

    xPCTag(1,2,3,4)=label_1label_2label_3label_4;

    To create the To Target blocks for the second and fourth properties in a block with at least four properties, use the following syntax:

    xPCTag(2,4)=label_1 label_2;
  6. From the File menu, click Save as. Enter a filename for your model. For example, enter

    xpctank1

You next task is to mark block signals if you have not already done so, and then create the user interface template model. See Marking Block Signals and Creating a Custom Graphical Interface.

Marking Block Signals

Tagging signals in your Simulink model allows the function SimulinkRealTime.utils.createInstrumentationModel to create From Target interface blocks. These interface blocks contain the signals you connect to display devices in your user interface model.

After you create a Simulink model, you can mark the block signals. This procedure uses the model xpctank1 (or xpctank) as an example. See Creating a Real-Time Application Model.

    Tip   The xpctank model blocks and signals may contain placeholder tags illustrating the syntax. As you create your own copy of the model using these procedures, replace these tags with your new tags or add the new tags using the multiple label syntax.

Note that you cannot select signals on the output ports of virtual blocks, such as Subsystem and Mux blocks. Also, you cannot select signals on software-triggered signal output ports.

  1. Open a Simulink model. For example, in the MATLAB Command Window, type:

    xpctank

    or

    xpctank1
  2. Point to a Simulink signal line, and then right-click.

  3. From the menu, click Properties.

    A Signal Properties dialog box opens.

  4. Select the Documentation tab.

  5. In the Description box, enter a tag to the signals for this line.

    For example, the block labeled TankLevel is an integrator with a single signal that indicates the level of water in the tank. Replace the existing tag with the tag:

    xPCTag(1)=water_level;

    The tag has the following format syntax:

    xPCTag(1, . . . index_n)=label_1 . . . label_n;

    For single dimension ports, the following syntax is also valid:

    XPCTag=label:
    • index_n — Index of a signal within a vector signal line. Begin numbering signals with an index of 1.

    • label_n — Name for a signal that will be connected to a From Target block in the user interface model. Separate the labels with a space, not a comma.

    label_1...label_n must consist of the same identifiers as those used by C/C++ to name functions, variables, and so forth. Do not use names like -foo.

    To create the From Target blocks in an user interface model for a signal line with four signals (port dimension of 4), use the following syntax:

    xPCTag(1,2,3,4)=label_1 label_2 label_3 label_4;

    To create the From Target blocks for the second and fourth signals in a signal line with at least four signals, use the following syntax:

    xPCTag(2,4)=label_1 label_2;

      Note:   Only tag signals from nonvirtual blocks. Virtual blocks are only graphical aids (see Nonvirtual and Virtual Blocks). For example, if your model combines two signals into the inputs of a Mux block, do not tag the signal from the output of the Mux block. Instead, tag the source signal from the output of the originating nonvirtual block.

  6. From the File menu, click Save as. Enter a filename for your model. For example, enter

    xpc_tank1

You next task is to mark block parameters if you have not already done so. See Marking Block Parameters. If you have already marked block signals, return to Creating a Custom Graphical Interface for additional guidance on creating a user interface template model.

Was this topic helpful?