SimulinkRealTime.target

Represent real-time application and target computer status

Description

A SimulinkRealTime.target object represents a currently loaded real-time application and target computer status.

Object provides access to methods and properties that do the following:

  • Start and stop the real-time application.

  • Read and set parameters.

  • Monitor signals.

  • Retrieve status information about the target computer.

  • Restart the target computer.

  • Load and unload the real-time application.

  • Start, stop, and retrieve information from the profiler.

Function names are case-sensitive. 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.

Some of the object properties and functions can be invoked from the target computer command line when the real-time application has been loaded.

Creation

target_object = SimulinkRealTime.target constructs a target object representing the default target computer.

When MATLAB® evaluates the return value on the development computer, it attempts to connect to the target computer. If the attempt succeeds, MATLAB prints Connected = Yes, followed by the status of the real-time application running on the target computer. If the attempt fails, MATLAB waits until the connection times out, and then prints Connected = No. To avoid the timeout delay, check that the target computer is operational and connected to the development computer, or suppress output with a terminating semicolon.

target_object = SimulinkRealTime.target(target_name) constructs a target object representing the target computer designated by target_name.

The SimulinkRealTime.target function accepts these arguments:

  • target_name — Name assigned to target computer (character vector or string scalar). For example, 'TargetPC1'.

  • target_object — Object representing target computer. For example, tg.

Before calling this function, make sure that you start the target computer with the Simulink® Real-Time™ kernel and apply the required Ethernet link settings.

This example creates a target object that communicates with the default target computer and reports the status of the default target computer. In this case, the target computer is connected to the development computer and is executing the loader.

target_object = SimulinkRealTime.target

This example creates a target object that communicates with target computer TargetPC1 and reports the status of the target computer. In this case, the target computer is not connected to the development computer.

target_object = SimulinkRealTime.target('TargetPC1')

Properties

expand all

Target Computer

This property is read-only.

Name of real-time application running on target computer, specified as a character vector or string scalar. This name is the name of the Simulink model from which the application was built. When the target computer starts, this value is 'loader'.

Communication timeout between the development and target computers, specified in seconds.

This property is read-only.

Communication status between the development and target computers, specified as character vector or string scalar.

This property is read-only.

CPU status for overload, specified as a character vector or string scalar. If the real-time application requires more CPU time than the model sample time provides, the kernel changes this value from 'none' to 'detected'. It then stops the current run. To keep this status from changing to 'detected', you must user a faster processor or specify a larger sample time.

This property is read-only.

Execution mode of the real-time application on the target computer, specified as a character vector or string scalar. Parameter settings determine the execution mode during Simulink Coder™ code generation.

This property is read-only.

Time since the kernel started running on the target computer, specified in seconds. This time is also the elapsed time since you started the target computer.

Current working folder on the target computer, specified as a character vector (for example, 'C:\') or string scalar.

Real-Time Execution

This property is read-only.

Average task execution time, specified in seconds.

Task execution time (TET) measures how long it takes the kernel to run for one base-rate time step. For a multirate model, use the profiler to find out what the execution time is for each rate.

Task execution time is nearly constant, with minor deviations due to cache, memory access, interrupt latency, and multirate model execution.

The TET includes:

  • Complete I/O latency.

  • Data logging for output, state, and TET, and the data captured in scopes.

  • Time spent executing tasks related to asynchronous interrupts while the real-time task is running.

  • Parameter updating latency. This latency is incurred if the Double buffer parameter changes parameter is set in the Simulink Real-Time Options node of the model Configuration Parameters dialog box.

The TET is not the only consideration in determining the minimum achievable sample time. Other considerations are:

  • Time required to measure TET.

  • Interrupt latency required to schedule and run one step of the model.

This property is read-only.

Execution time of real-time application since your real-time application started running, specified in seconds. When the real-time application stops, the kernel displays the total execution time.

This property is read-only.

Maximum task execution time, specified in seconds. Corresponds to the slowest time (longest measured time) required to update model equations and post outputs.

This property is read-only.

Minimum task execution time, specified in seconds. Corresponds to the fastest time (smallest measured time) required to update model equations and post outputs.

Time between samples (step size), in seconds, for updating the model equations and posting the outputs.

Note

Some blocks produce incorrect results when you change their sample time at run time. If you include such blocks in your model, the software displays a warning message during model build. To avoid incorrect results, change the sample time in the original model, and then rebuild and download the model.

See Limits on Sample Time.

This property is read-only.

Execution status of real-time application, specified as character vector or string scalar.

Time when the real-time application stops running, specified in seconds, as character vector, or as string scalar. The initial value is set in the Solver pane of the Configuration Parameters dialog box.

When the ExecTime reaches StopTime, the application stops running. If you specify the special value 'Inf', the real-time application runs until you manually stop it or restart the target computer.

This property is read-only.

Storage in the MATLAB workspace for task execution time, specified as a vector of double.

Signal Visualization

The values are the following meaning:

  • 'Normal' — Indicates time-equidistant logging. Logs a data point at every time interval.

  • Double — Indicates value-equidistant logging. Logs a data point only when an output signal from the OutputLog changes by the specified difference in signal value (increment).

This property is read-only.

Maximum number of samples for each logged signal, specified as an unsigned integer.

This property is read-only.

Number of times the circular data logging buffer wraps, specified as an unsigned integer. The buffer wraps each time the number of samples exceeds MaxLogSamples.

This property is read-only.

Number of observable signals in Simulink model, specified as an unsigned integer. Nonobservable signals are not included in this value.

Note

  • Signal access by signal index will be removed in a future release. Access signals by signal name instead.

  • This parameter will be removed in a future release.

This property is read-only.

Storage in MATLAB workspace for output or Y-vector, specified as a matrix.

This property is read-only.

List of index numbers, one per scope, specified as a vector of unsigned integers.

Flag set to view the list of signals from your Simulink model, specified as character vector or string scalar. MATLAB displays the signal list when you display the properties for a target object.

This property is read-only.

List of observable signals, specified as a vector containing the following values for each signal:

  • Index — ID used to access the signal.

  • Value — Value of the signal.

  • Type — Data type of the signal.

  • Block name— Hierarchical name of the Simulink block that the signal comes from.

  • Label — Label that you have assigned to this signal.

This list is visible only when ShowSignals is set to 'on'.

This property is read-only.

Storage in MATLAB workspace for state or X-vector, specified as a matrix.

This property is read-only.

Storage in the MATLAB workspace for time or T-vector, specified as a vector of double.

Parameter Tuning

This property is read-only.

Number of tunable parameters in Simulink model, specified as an unsigned integer. Nontunable (nonobservable) parameters are not included in this value.

Note

  • Parameter access by parameter index will be removed in a future release. Access parameters by parameter name instead.

  • This parameter will be removed in a future release.

This property is read-only.

List of tunable parameters, displayed as a vector containing the following values for each parameter:

  • Value — Value of the parameter in a Simulink block. If the parameter is a structure, the value is displayed with vector brackets.

  • Type — Data type of the parameter.

    Note

    Simulink Real-Time does not support parameters of multiword data types.

  • Size — Size of the parameter. For example, scalar, 1-by-2 vector, or 2-by-3 matrix, structure.

  • Parameter name — Name of the parameter in a Simulink block.

    If the parameter is a field of a structure, the name is displayed in the form structname.fieldname.

  • Block name — If the parameter is a block parameter, the block name is the hierarchical name of the Simulink block containing the parameter. If the parameter is a MATLAB variable that provides the value for a block parameter, the block name is the empty character vector.

This list is visible only when ShowParameters is set to 'on'.

Flag set to view the list of parameters from your Simulink model, specified as character vector or string scalar. MATLAB displays the parameter list when you display the properties for a target object.

Profiler

The profiler states have the following meaning:

  • Ready — The profiler starts in this state and remains in it until the profiler runs.

    If the profiler runs, it reenters this state if the profiler:

    • Stopped without collecting data.

    • Collected data and the data was downloaded to the development computer.

    • Was reset.

  • Running — The command to start the profiler succeeded.

    If a real-time application is running, the profiler collects data.

    If a real-time application is not running, the profiler initializes and waits. When a real-time application starts, the profiler starts collecting data.

  • DataAvailable — The command to stop the profiler succeeded. The profiler collected data, but the data has not been downloaded to the development computer. In this state, an attempt to restart the profiler produces the following results:

    • If an application is running, calling this function returns an error. Download the data or reset the profiler before restarting it.

    • If an application is not running, calling this function restarts the profiler, and this operation discards the existing profile data from the target computer.

Object Functions

pingTest communication between development and target computers
rebootRestart target computer
closeClose connection between development and target computers
createStandAloneCreate a standalone real-time application for target computer
loadDownload real-time application to target computer
unloadRemove real-time application from target computer
startStarts execution of real-time application on target computer
stopStops execution of real-time application on target computer
addscopeCreate a scope of specified type
getscopeReturn scope identified by scope number
remscopeRemove scope from target computer
getlogPortion of output logs from target object
importLogDataImport buffered logging data to the active session of the Simulation Data Inspector
getsignalValue of signal
getsignalidSignal index from signal hierarchical name
getsignalidsfromlabelVector of signal indices
getsignallabelSignal label for signal index
getsignalnameSignal name from index list
getparamRead value of observable parameter in real-time application
setparamChange value of tunable parameter in real-time application
getparamidParameter index from parameter hierarchical name
getparamnameBlock path and parameter name from parameter index
loadparamsetRestore parameter values saved in specified file
saveparamsetSave real-time application parameter values
startProfilerStart profiling service on target computer
stopProfilerStop profiling service on target computer
getProfilerDataRetrieve profile data object
resetProfilerReset profiling service state to Ready
getDiskSpaceReturn free space and total space on the drive, in bytes

Examples

collapse all

Build and download xpcosc, execute real-time application in external mode.

Open, build, and download real-time application

ex_model = 'xpcosc';
open_system(ex_model);
ex_scope = [ex_model '/Scope'];
open_system(ex_scope)
rtwbuild(ex_model);
tg = slrt('TargetPC1');
load(tg,ex_model);
tg
Target: TargetPC1
   Connected            = Yes
   Application          = xpcosc
   Mode                 = Real-Time Single-Tasking
   Status               = stopped
   CPUOverload          = none

   ExecTime             = 0.0000
   SessionTime          = 769.0726
   StopTime             = 0.200000
   SampleTime           = 0.000250
   AvgTET               = NaN
   MinTET               = Inf
   MaxTET               = 0.000000
   ViewMode             = 0

   TimeLog              = Vector(0) 
   StateLog             = Matrix (0 x 2)
   OutputLog            = Matrix (0 x 2)
   TETLog               = Vector(0) 
   MaxLogSamples        = 16666
   NumLogWraps          = 0
   LogMode              = Normal
   ProfilerStatus       = Ready

   Scopes               = No Scopes defined  
   NumSignals           = 7
   ShowSignals          = off

   NumParameters        = 7
   ShowParameters       = off

Prepare and run simulation in external mode for 10 seconds.

tg.StopTime = 10;
set_param(ex_model,'SimulationMode','External'); 
set_param(ex_model,'SimulationCommand','Connect');
set_param(ex_model,'SimulationCommand','Start');
pause(10);
set_param(ex_model,'SimulationCommand','Stop');
set_param(ex_model,'SimulationCommand','Disconnect'); 

The output looks like this figure.

Unload real-time application

unload(tg)
Target: TargetPC1
   Connected            = Yes
   Application          = loader

Introduced in R2014a