Documentation

Real-Time Scope Objects

The Simulink® Real-Time™ software uses scope objects to represent scopes on the target computer. Use scope object functions to view and collect signal data.

The Simulink Real-Time software uses scopes and scope objects as an alternative to using Simulink scopes and external mode. A scope can exist as part of a Simulink model system or outside a model system.

  • A scope that is part of a Simulink model system is a Scope block. You add a Simulink Real-Time Scope block to the model, build a real-time application from that model, and download that application to the target computer.

  • A scope that is outside a model is not a Scope block. For example, if you create a scope with the SimulinkRealTime.target.addscope function, that scope is not defined within the model. After the model has been downloaded and initialized, you add this scope to the model.

This difference affects when and how the scope executes to acquire data.

Scope blocks inherit sample times. A Scope block in the root model or a normal subsystem executes at the sample time of its input signals. A Scope block in a conditionally executed (triggered/enabled) subsystem executes whenever the containing subsystem executes. In the latter case, the scope can acquire samples at irregular intervals.

A scope that is not part of a model executes at the base sample time of the model. For signals with a sample time longer than the base sample time, it acquires repeated identical samples. For example, assume that the model base sample time is 0.001 and that you dynamically add to the scope a signal whose sample time is 0.005. The scope acquires five identical samples for this signal at each signal sample time.

Understanding the structure of scope objects helps you to use the MATLAB® command-line interface to view and collect signal data. A scope object on the development computer represents a scope on the target computer. You use scope objects to observe the signals from your real-time application during a real-time run or analyze the data after the run is finished.

To create a scope object:

  • Add a Simulink Real-Time Scope block to your Simulink model. To determine the scope type, set the Scope type parameter. To create a scope on the target computer, build and download the model. Use the real-time application object function SimulinkRealTime.target.getscope to create a scope object on the development computer.

  • Build and download a model. Use the real-time application object function SimulinkRealTime.target.addscope to create a scope on the development computer. To determine the scope type, pass one of the following values as input parameter: target, host, or file.

Upon creation, the Simulink Real-Time software assigns the required scope object class for the scope type: SimulinkRealTime.targetScope, SimulinkRealTime.hostScope, or SimulinkRealTime.fileScope.

A scope object has properties and functions specific to its scope type, as well as properties and functions in common with the other scopes. The scope object functions allow you to control scopes on your target computer.

To control the real-time application from a target computer keyboard, use target computer commands (see Control Real-Time Application at Target Computer Command Line).

Display Scope Object Properties for One Scope

To list the properties of a single scope object, sc1, in the MATLAB window, type:

tg = slrt;
sc1 = getscope(tg,1)

MATLAB creates the scope object sc1 from a previously created scope.

The current scope properties are uploaded to the development computer. MATLAB displays a list of the scope object properties with the updated values. Because sc1 is a vector with a single element, you could also type sc1(1) or sc1([1]).

    Note:   Only scopes of type host store data in the properties scope_object.Time and scope_object.Data.

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

Display Scope Object Properties for Multiple Scopes

To list the properties of the current scope objects associated with the real-time application object tg, in the MATLAB window, type:

tg = slrt;
getscope(tg)

SimulinkRealTime.target.getscope supports vector arguments. For example, to list the first and third scopes, type:

getscope(tg,[1,3])

To assign a list of current scopes to a variable, type:

allscopes = getscope(tg)

For a list of real-time application object properties, see the target function SimulinkRealTime.target.

Set Scope Property Values

With the Simulink Real-Time software, you can use object property syntax to set a single scope object property.

scope_object.property_name = new_property_value

For example, to change the trigger mode for scope 1, in the MATLAB window, type:

tg = slrt;
sc1 = getscope(tg, 1);
sc1.triggermode = 'signal'

You cannot use dot notation to set vector object properties. To assign a property value to a vector of scopes, use the set function. For example, assume you have two scopes, 1 and 2. First assign a vector containing these scopes to the variable sc12:

sc12 = getscope(tg, [1,2]);

To set the NumSamples property of these scopes to 300, type:

set(sc12, 'NumSamples', 300);

To get a list of the writable properties, type scope_object.

    Note:  

    • You cannot set a property of a vector of scopes to a vector of property values. For example, you cannot set property NumSamples of vector sc12 to [100,200].

    • 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.

Get Scope 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 to get scope property values.

scope_object_vector(index_vector).property_name

For example, to get the number of samples from scope 1, in the MATLAB window, type:

tg = slrt;
sc1 = getscope(tg, 1);
sc1.NumSamples

To get the values of vector object properties set using the set function, you can use the corresponding get function. For example, assume you have two scopes, 1 and 2, with a NumSamples property of 300.

First assign a vector containing these scopes to the variable sc12.

sc12 = getscope(tg, [1,2]);

To get the value of NumSamples for these scopes, type:

get(sc12, 'NumSamples')

You get a result like:

ans = 
    [300]
    [300]

Although you cannot use dot notation to set the values of vector object properties, you can use it to get those values:

sc12.NumSamples

You get a result like:

ans = 
    300

ans = 
    300

To get a list of readable properties, type scope_object. The property values are listed in the MATLAB window.

    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 Scope Object Functions

Use the function syntax to run a scope object functions:

function_name(scope_object, argument_list)

Unlike properties, for which partial but unambiguous names are permitted, enter function names in full, in lowercase. For example, to add signals to the first scope in a vector of all scopes, in the MATLAB window, type:

allscopes = getscope(tg)
addsignal(allscopes(1), [0,1])
Was this topic helpful?