Main Content

Simulink Real-Time App Generator

Generate instrument panel app to interact with target computer and real-time application running on target computer

Since R2022a

Description

Simulink® Real-Time™ App Generator helps you generate an instrument panel app that interacts with the target computer and real-time application running on the target computer. You can select signals and parameters in your model to represent as instrument panel controls and configure the controls before generating the app.

To use the Simulink Real-Time App Generator, open the App Generator from the Real-Time tab in the Simulink Editor and use the App Generator for these tasks:

  • Open a model file SLX or real-time application file MLDATX, and create an instrument panel app.

  • Select signals and parameters to add to an instrument panel app.

  • Configure controls for instrument panel app.

  • Validate instrument bindings against real-time application MLDATX file.

  • Create instrument panel app.

  • Save an App Generator session file MAT, and open it in a future App Generator session.

By using the parts of the Simulink Real-Time App Generator, you can instrument signals and parameters from your real-time application, binding them to controls in a generated instrument panel. The generator lets you configure options for generating the instrument panel and configure the properties of the instrument panel controls. Use these parts of the App Generator to configure and generate an instrument panel:

Designer Toolstrip Operations

The App Generator controls on the Designer toolstrip let you add, remove, edit, and validate signal and parameter bindings between the real-time application to controls in the generated instrument panel app.

ControlsApp Generator Operations

Use the Options button pull down menu to configure options for instrument panel app generation. The options include:

  • Toolstrip — Provide target computer controls at top of instrument panel.

  • Menu — Provide target computer controls in a menu on the instrument panel.

  • Status bar — Add status bar to the instrument panel.

  • TET Monitor — Add task execution time monitor to the instrument panel.

  • Instrumented signals — Include a plot of instrumented signals on a set of axes in the instrument panel. When you enable this option, all instrumented signals are included on a single axes. This all-signals axes control is not configurable. You also can add axes controls for individual signals. The individual-signal axes controls are configurable in the property panel. See Property Panel Operations.

    Instrumented nonvirtual bus signals are not included on the axes generated by the Instrumented signals option. You can add individual axes for nonvirtual bus signals.

  • Dashboard blocks — Import dashboard blocks from model to the instrument panel.

  • Use Grid Layout — Arrange components using grids on the instrument panel.

  • Callback — Process signals before displaying on the instrument panel.

  • Configure Components — Configure options for Simulink Real-Time App Designer components and select name for instrument panel app.

  • Settings — Enable automatic validation of instrument-to-control bindings during app generation.

Use the Target Events button to add callback code for target computer events. The App Generator adds the callback code for events when generating the app, and you can edit the callback code further by using the Code View in the App Designer. For more information, see Add Callbacks for Target Computer Events.

Use the Add From Model button to open a model in bind mode and use the model to select signals and parameters for the generated instrument panel. The App Generator Bind Mode message box remains active until you close bind mode for the model in the Simulink Editor.

When you select a single signal or a parameter from the Bindings tab, you can highlight that selected item in the model. If you select a workspace variable from the Bindings tab, clicking the Highlight in Model button opens the model base workspace in Model Explorer.

When you select multiple signals or parameters from the Bindings tab, you can use the Mass Edit button to edit the instrument binding configurations for the selected items. You can change the control type, change the control name, and select whether to make the control name unique.

Use the Remove button to delete the selected instrument bindings from the Bindings tab for instrument panel generation.

For the real-time application MLDATX file, use the Validate button to check the instrument binding configurations in the Bindings tab. If the MLDATX file is not available, the App Generator issues a error.

Use the Generate App button to create an App Designer instrument panel for the real-time application by using the instrument binding configurations from the Bindings tab and by using the selected instrument panel options from the Options button.

After generating an App Designer instrument panel MLAPP file, you can add instrument bindings with their controls to the instrument panel. To enable the Add to App button:

  1. Add a signal or parameter to the Bindings tab.

  2. Select the added signal or parameter in the Bindings tab.

  3. Click the Add to App button and select the MLAPP file for the instrument panel to which you would like to add the control.

Tip

The Add to App workflow helps you add instrument bindings with their controls to a generated instrument panel. This approach lets you add to a generated instrument panel that you have customized in App Designer.

Signals and Parameters Pane Operations

The Signals and Parameters pane helps you instrument the signals, parameters, and data in a real-time application. The tree hierarchy in the pane divides into Model and External Data, Named Signals, and the real-time application model signals and parameters. To add signals, parameters, or data to the instrument panel, select items from the Signals And Parameters pane, and click the Add selected button.

At the top of this pane, the filter box and filter options help you search for signals and parameters. The figure shows a search for signals in the slrt_ex_sf_car model that contain the text torque.

You can filter the display in the Signals And Parameters pane.

Bindings Tab Operations

When you select a signal, parameter, or variable in the Bindings tab, the Parameter or Signal configuration pane opens. This pane lets you configure the App Designer control in the instrument panel for the selected item. If you select multiple signals or parameters, you can use the Mass Edit button to configure the controls for the group of selected items.

Property Panel Operations

When you select a signal, parameter, or variable in the Bindings tab, the Parameter or Signal property panel opens. This panel lets you configure the App Designer control in the instrument panel for the selected item. You can change the displayed fields in the Parameter or Signal property panel by using the selection for the Control Type field.

Generate an App Designer app by using the Simulink Real-Time App Generator.

Open the Simulink Real-Time App Generator App

From the Simulink Editor, in the Real-Time tab, select Review Results > App Generator. Or, in the MATLAB® Command Window, type:

slrtAppGenerator

If you open the App Generator from a model, the App Generator populates the Signals and Parameters pane with information from the model.

Examples

expand all

This example shows how to configure instrument panel controls for signals and parameter, then create an instrument panel app by using the App Generator. This example uses example model slrt_ex_osc.

  1. Open example model slrt_ex_osc. In the MATLAB Command Window, type:

    openExample('slrealtime/SlrtAddIOBlocksToSimulinkModelExample', ...
        'supportingFile','slrt_ex_osc.slx')
  2. Build the model, creating a real-time application file MLDATX.

  3. Open the Simulink Real-Time App Generator. In the Real-Time tab, select Review Results > App Generator.

  4. To create an instrument panel from the real-time application file MLDATX, select New > New, click No to remove the current session, and select the MLDATX file. For information about the difference between developing an instrument panel from a model SLX file or a real-time application MLDATX file, see the Tip About MLDATX and SLX Files..

  5. Add signals and parameters to the instrument panel app. From the Signals and Parameters pane, select the Amplitude parameter, the Frequency parameter, and the XfrFnc signal. Click the Add Selection button.

  6. Configure each control by clicking on its Control Type entry and editing the selections for the control. This figure shows a possible configuration for this instrument panel.

    By editing the Control Type, you select the app interface for a signal or parameter in the generated app.

  7. To create the instrument panel app, click the Generate App button.

    After creating the app, you can open it in App Designer to further customize the instrument panel.

    The App Generator adds controls to your instrument panel that let the panel interface with the real-time application. These controls include the target computer selector, connect button, load application button, start/stop button, stop time field, and system log. Any instrumented signals from the model are added in an axis component. For more information, see Create App Designer Instrument Panels by Using Simulink Real-Time Components.

  8. Tip About MLDATX and SLX Files.  You can develop an instrument panel app in the App Generator from a model SLX file (if you start the App Generator from the Real-Time tab in the Simulink Editor) or from a real-time application MLDATX file. It is recommended that you develop the instrument panel based on the MLDATX file, because—when developing from the MLDATX file—the App Generator only lists the signals and parameters that are present in the generated code. If you develop the instrument panel based on the SLX file, the App Generator can list more signals than are present in the generated code. These signals include virtual signals and signals to Scope blocks.

This example shows how to open a real-time application in the App Generator, add signals and parameters to an instrument panel app from the real-time application, and add signals and parameters to the instrument panel app from the model that corresponds to the real-time application..

  1. Open the App Generator. In the MATLAB Command Window, type:

    slrtAppGenerator
  2. To create a new instrument panel app, click the New button and select the real-time application file slrt_ex_osc.mldatx. You created this file in Configure Instrument Panel Controls and Create App.

  3. Add signals and parameters to the instrument panel app. From the Signals and Parameters pane, select the Amplitude parameter, the Frequency parameter, and the XfrFnc signal. Click the Add Selection button.

  4. To add signals and parameters from the model that corresponds to the real-time application, click the Add From Model button.

    The App Generator opens the model and puts the model in bind mode for signal and parameter selection. For more information about bind mode, see Add Instruments to Real-Time Application from Simulink Model.

  5. To return to the App Generator, close bind mode in the model.

  6. To create the instrument panel app, click the Generate App button.

Because conversion functions are needed to transform the value of a uibuttongroup 'SelectObject' property to a usable real-time parameter value (and vice-versa), it is recommended that you use the App Generator to add button groups for parameters. The App Generator adds the needed conversion code as part of the instrument panel generation process.

  1. Follow the steps in Open Real-Time Application and Create App, stopping before generating the instrument panel.

  2. Select and add a parameter from the App Generator Signals and Parameters pane to the Bindings tab.

  3. Select the parameter in the Bindings tab and change the Control Type to Button Group.

  4. Configure the control in the Properties panel. The figure shows an example parameter setup from the slrt_ex_osc model.

    The parameter setup for button group control has many properties.

  5. Generate the instrument panel and open it in App Designer.

    The generated instrument panel has a button group to apply values to the parameter. To examine the generated conversion functions, open the Code View.

  1. Follow the steps in Open Real-Time Application and Create App, stopping before generating the instrument panel.

  2. Click the Target Events button.

  3. Select the Connected event from the list, click in the callback field, and add the function command:

    disp('Connected to target computer')
  4. Select the Loaded event from the list, click in the callback field, and add the function command:

    disp('Loaded MLDATX on target computer')
  5. To add these callbacks, click Apply. To close the Callback Editor dialog box, click OK.

  6. Generate the instrument panel and open it in App Designer.

    The generated instrument panel has callback code for the target computer events. To examine the generated conversion functions, open the Code View and see the added methods.

    methods
        function ConnectedFcn(app, event)
            disp('Connected to target computer')
        end
        function LoadedFcn(app, event)
            disp('Loaded MLDATX on target computer')
        end
    end

    When you run the app and connect, your ConnectedFcn callback executes automatically. When you load a real-time application, your LoadedFcn callback executes automatically.

Related Examples

Programmatic Use

expand all

slrtAppGenerator opens the Simulink Real-Time App Generator. Operations that the Simulink Real-Time App Generator UI adds to an instrument panel app correspond App Designer controls that are customized for your real-time application. For more information about these controls, see slrealtime.ui Properties.

Version History

Introduced in R2022a

expand all