Contenido principal

Create App Designer Instrument Panels by Using App Generator

You can create App Designer instrument panels to interface with real-time applications by using the App Generator button on the Real-Time tab in the Simulink® Editor. By using the App Generator, you can generate an instrument panel for selected signals and parameters in your model. You can open the generated app in App Designer to customize the instrument panel.

To create an instrument panel for your model by using the App Generator button:

  1. Open the Simulink Real-Time™ model.

  2. In the Simulink Editor, on the Real-Time tab, click Review Results > App Generator.

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

  4. In the App Generator, select Signals and Parameters in the model to add as components on the instrument panel. Click the Add to panel button.

  5. After you add each signal or parameter, configure the Control Name and Control Type. The figure shows some App Generator selections for the slrt_ex_osc model.

    Configure App Generator controls for the slrt_ex_osc model.

  6. After configuring the Control Name and Control Type for the signals and parameters, click the Generate App button.

  7. To customize the generated application, click the Open in App Designer button.

The App Generator adds controls to your instrument panel that enable the panel to 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.

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.

Open Real-Time Application and Create App

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 by Using Simulink Editor.

  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.

Bind Parameter to Toggle or Radio Button Group

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.

Add Callbacks for Target Computer Events

Callback functions add functionality to app controls. You can set up callback functions to execute based on real-time application events.

  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.

Select Multiple Controls and Edit Properties (Mass Edit)

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, select whether to make the control name unique, and change tab placement of the control in the generated app.

  1. Select multiple signal or parameter bindings for mass editing.

  2. From the Mass Edit button, select the type of mass edit from the drop down menu. From this level you can Change control tab placement or select a mass edit type. The selection of mass edit type opens different editing methods, selecting:

    • Change control type opens the selection list of controls.

    • Change control properties opens the property inspector dialog box.

    • Change control name is an edit field for modifying the control names when the Control Type is Parameter Table or Signal Table.

    • Make control name unique adds a unique suffix to controls with identical names in a Parameter Table or Signal Table.

  3. Apply the edit to the signal or parameter bindings en masse.

    The Mass Edit button lets you apply changes to multiple signal or parameter bindings.

Create Multiple Tabs for App and Assign Controls (Layout)

Use the Layout button to open the Layout Options dialog box. From this dialog box, you can add or remove tabs in the generated app. Also, this dialog box lets you select grid usage for layout and choose whether the tabs open as windows in the generated app.

  1. Click the Layout button.

  2. To add a tab in the generated app, from the Layout Options dialog box, click the Add button. To remove a tab from the generated app, select an existing tab from the list and click the Remove button.

  3. You can configure generation options for the tabs by selecting the Use the Use grid layout for each tab checkbox and the Open tabs as windows when app starts checkbox.

  4. Close the dialog box when done.

See Also

|

Topics