Documentation

Real-Time Application Objects

The Simulink® Real-Time™ software uses a SimulinkRealTime.target object to represent the target kernel and your real-time application. Use real-time application object functions to run and control real-time applications on the target computer with scope objects to collect signal data.

An understanding of the real-time application object properties and functions helps you to control and test your real-time application on the target computer.

A real-time application object on the development computer represents the interface to a real-time application and the kernel on the target computer. You use real-time application objects to run and control the real-time application.

When you change a real-time application object property on the development computer, information is exchanged with the target computer and the real-time application.

To create a real-time application object:

  1. Build a real-time application. The Simulink Real-Time software creates a real-time application object during the build process.

  2. Use the real-time application object function SimulinkRealTime.target. In the MATLAB® Command window, type tg = SimulinkRealTime.target.

A SimulinkRealTime.target object has properties and functions specific to that object. The real-time application object functions allow you to control a real-time application on the target computer from the development computer. You enter real-time application object functions in the MATLAB window on the development computer, or you can use MATLAB code scripts. To access the help for these functions from the command line, use the syntax:

doc SimulinkRealTime.target/function_name

If you want to control the real-time application from the target computer, use target computer commands (see Control Real-Time Application at Target Computer Command Line).

Create Real-Time Application Objects

To create a real-time application object:

  1. Build a real-time application. The Simulink Real-Time software creates a real-time application object during the build process.

  2. To create a specific real-time application object, or to create multiple real-time application objects in your system, use the real-time application object function SimulinkRealTime.target with arguments. For example, to create a real-time application object for target TargetPC1, in the MATLAB Command Window, type:

    tg = SimulinkRealTime.target('TargetPC1')

    The resulting real-time application object is tg.

    Using this function clarifies which application object is associated with a particular target computer.

  3. To check a connection between development and target computers, use the target function SimulinkRealTime.target.ping. For example, type:

    ping(tg)
  4. To create a real-time application object for the default target computer, use the creation function SimulinkRealTime.target without arguments. For example, in the MATLAB Command Window, type:

    tg = SimulinkRealTime.target

    The resulting real-time application object is tg.

    Note:   If you use SimulinkRealTime.target without arguments to create a real-time application object, use Simulink Real-Time Explorer to configure your target computer. Doing so clarifies which real-time application object is associated with a particular target computer.

Display Application Object Properties

You might want to list the real-time application object properties to monitor a real-time application. The properties include the execution time and the average task execution time.

After you build a real-time application and real-time application object from a Simulink model, you can list the real-time application object properties. This procedure uses the default real-time application object name tg as an example.

  1. In the MATLAB window, type:

    tg = slrt;

    The current real-time application properties are uploaded to the development computer. MATLAB displays a list of the real-time application object properties with the updated values.

    The real-time application object properties for TimeLog, StateLog, OutputLog, and TETLog are not updated at this time.

  2. Type:

    start(tg)

    The Status property changes from stopped to running. The log properties change to Acquiring.

For a list of real-time application object properties with a description, see SimulinkRealTime.target.

Set Real-Time Application Object Property Values

You can change a real-time application object property by using the Simulink Real-Time dot notation on the development computer. (For limitations on target property changes to sample times, see Alternative Configuration and Control Methods.)

With the Simulink Real-Time software, you can use object property syntax to change the real-time application object properties.

target_object.property_name = new_property_value 

For example, to change the stop time for the real-time application running on target tg, in the MATLAB window, type:

tg = slrt;
tg.StopTime = 1000

When you change a real-time application object property, the new property value is downloaded to the target computer. The Simulink Real-Time kernel then receives the information and changes the behavior of the real-time application.

To get a list of the writable properties, type target_object. The build process assigns the default name of the real-time application object to tg.

Get Real-Time Application Object Property Values

You can list a property value in the MATLAB window or assign that value to a MATLAB variable. With the Simulink Real-Time software, you can use object property syntax.

target_object.property_name

For example, to access the stop time for the real-time application running on target tg, in the MATLAB window, type:

tg = slrt;
endrun = tg.StopTime

To get a list of readable properties, type target_object. Without assignment to a variable, the property values are listed in the MATLAB window.

Signals are not real-time application object properties. To get the value of the Integrator1 signal from the model xpcosc, in the MATLAB window, type:

outputvalue = getsignal(tg, 0)

0 is the signal index.

    Note:   Function names are case sensitive. You must type the entire name. Property names are not case sensitive. You do not need to type the entire name, as long as the characters you do type are unique for the property.

Use Real-Time Application Object Functions

Use the function_name(target_object, argument_list) syntax to run a real-time application object function.

Unlike properties, for which partial but unambiguous names are permitted, you must enter function names in full, in lowercase. For example, to add a target scope with a scope index of 1, in the MATLAB window, type:

tg = slrt;
addscope(tg,'target',1)
Was this topic helpful?