Main Content

Control and Update Stimulation of Inports to Real-Time Application

You can stream data to the inports of a real-time application on a target computer by using the Target.Stimulation object and functions. The functions enables you to control inport stimulation for individual or all inports and monitor stimulation status.

To load data to the inports, create a time series object by using, for example the timeseries function. Load the object into the inport. Do not pause or stop the stimulation of inports before or during the stimulation. A pause or stop generates a stimulation error.

To control or monitor stimulation of inports in a real-time application:

  • Start the stimulation of a specific inport or all inports by using the start function.

  • Pause the stimulation of a specific inport or all inports by using the pause function.

  • Stop the stimulation of a specific inport or all inports by using the stop function.

  • Get the status of stimulation of inports by using the getStatus function.

  • Load data to specific inports by using the reloadData function.

Stimulate Root Inport by Using MATLAB Language

This example shows how to stimulate root inports in a model by using the Stimulation object and related functions:

  • start

  • stop

  • getStatus

  • reloadData

  • pause

Open Model and Map Inport to Wave Data

Open model slrt_ex_osc_inport. Save the model to a working folder. Map the inport to use square wave data. For inport In1, interpolated is off.

model = ('slrt_ex_osc_inport');
open_system(model);
load('slrt_ex_inport_square.mat');
waveform = square;
set_param(model,'ExternalInput','waveform');
set_param(model,'LoadExternalInput','on');
set_param(model,'StopTime','Inf');

Build Model and Download Real-Time Application

Build, download, and execute the real-time application.

evalc('slbuild(model)');
tg = slrealtime('TargetPC1');
load(tg,model);

Stimulate Root Inport Data

Start root inport stimulation of inports 1. Open Scope block and observe results.

start(tg.Stimulation,[1]);
start(tg);

Pause root inport stimulation of inport 1.

pause(tg.Stimulation,[1]);

Stop and start the stimulation of inport 1.

stop(tg.Stimulation,[1]);
start(tg.Stimulation,[1]);

Check the status of stimulation of the inports.

getStatus(tg.Stimulation,'all');

Create a time-series object to load data to an inport.

sampleTime = 0.1;
endTime = 10;
numberOfSamples = endTime * 1/sampleTime + 1;
timeVector = (0:numberOfSamples) * sampleTime;
u = timeseries(timeVector*10,timeVector);

Object u is created for 10 seconds. Load it to the inport 1. Stimulation of an inport should be stopped before loading data.

stop(tg.Stimulation,[1]);
reloadData(tg.Stimulation,[1],u);

Stop real-time application and close all.

stop(tg);
bdclose('all');

See Also

|