%% Apply Simulink Real-Time Model Template to Create Real-Time Application
% This example shows how to use the Simulink Real-Time template to create 
% a Simulink model. Starting from the model template provides a new model 
% that has configuration parameters set up for building a real-time 
% application.
% 
% To see the Simulink Real-Time commands for each operation in this example, 
% <matlab:openExample('slrealtime/ApplySlrealtimeModelTemplateToCreateRtAppExample') view the example code>.
%% Create Simulink Model from Template 
% To create a Simulink model from the Simulink start page, in the MATLAB Command Window, type:
% 
% |simulink|
%  
% Select the Simulink Real-Time template from the start page and create the |exampleSlrealtimeApp| 
% model. Or, in the Command Window, use the |Simulink.createFromTemplate|
% command. See code for this script for full syntax.
h_model = Simulink.createFromTemplate(fullfile(matlabroot,'toolbox','slrealtime','simulink','coder','slrealtimeTemplate.sltx'));
open_system(h_model);
save_system('untitled','exampleSlrealtimeApp');
%% Blocks, Connections, and Data Logging in the Model 
% The Simulink Real-Time model template contains a Gain block that connects
% a Signal Generator to an Outport. The Gain block output is marked for 
% logging with the Simulation Data Inspector (SDI).
% 
%% Simulate Real-Time Application and View Logged Data
% Build the real-time application, run it on the target computer, and view 
% the logged data:
%
% *1.* Make sure that the development computer has a connection to the target computer.
% 
% *2.* Build the model and download the real-time application to the target computer. 
% On the *Real-Time* tab, click *Run on Target*. Or, use the |rtwbuild|
% command and the |load| command.
% 
% *3.* Run the real-time application and log data by using the |start| command.
% 
% *4.* Open the Simulation Data Inspector by double-clicking the Simulation Data Inspector icon on the
% Gain block output signal or by using the |Simulink.sdi.view| command.
% 
evalc('rtwbuild(''exampleSlrealtimeApp'')');
tg = slrealtime;
load(tg,'exampleSlrealtimeApp');
start(tg);
Simulink.sdi.view
%% More Information
% * <docid:slrealtime_gs#btifh_s>
% * <docid:slrealtime_gs#btifibv>
% * <docid:simulink_ref#mw_df415982-8312-413a-8c53-28d643c76e75>
%
% Copyright 2020 The MathWorks, Inc.