Main Content

Application

Represent application files on development computer

Since R2020b

Description

An application object represents application files on the development computer. You can create application objects for real-time applications that you build from models.

An application object provides access to methods and properties that let you work with the application blocks and signals.

Creation

app_object = slrealtime.Application(application_name) creates an object that you can use to manipulate real-time application files on the development computer. You can create the object only after the real-time application has been built.

The slrealtime.Application function accepts these arguments:

  • application_name — Name of real-time application (character vector or string scalar). For example, 'slrt_ex_osc_inport'.

    This argument is the file name without the .mldatx file extension of the MLDATX file that the build produces on the development computer.

  • app_object — Represent real-time application files on the development computer.

    This argument provides access to methods that manipulate the real-time application files.

Create an application object for real-time application slrt_ex_osc_inport.

app_object = slrealtime.Application('slrt_ex_osc_inport');

Example: Extract ASAP2 File

Example: Update Root-Level Inport Data

Example: Get and Set Application Options

Example: Get Application Signals and Parameters

Properties

expand all

This property is read-only.

Name of real-time application created when you built the application.

This property is read-only.

Name of the Simulink model from which you build the real-time application.

You can assign arbitrary vector data to the UserData field. You can access this data from only the development computer.

Example: {'This string', 10}

This property is read-only.

Use the Options property to get and set real-time application options. For an example, see Get and Set Application Options. The options are:

  • fileLogMaxRuns selects the number of simulation runs that are stored for the real-time application when file logging is enabled.

  • loglevel selects the log message level for the target computer system log. The available levels are error, warning, info, debug, and trace.

  • overrideBaseRatePeriod selects an override value for the application base rate period.

  • pollingThreshold selects the sample rate below which the RTOS thread scheduler switches polling mode, instead of interrupt-driven mode, for clocking the real-time application. Polling mode can be useful for reducing sample time jitter. But, enabling this option causes the real-time application to consume a CPU core completely to clock and execute the base rate.

  • startupParameterSet indicates the start up parameter set from the ParameterSet objects that have been added to the Application object. To change the selection, use the updateStartupParameterSet function.

  • stoptime selects the stop time for the real-time application.

Object Functions

addParamSetAdd a parameter set to a real-time application
extractASAP2Extract generated A2L file from real-time application file
getAllFileLogBlocksReturns block paths corresponding to File Log blocks in application
getFileLogDecimationReturns decimation value of File Log block based on block path
getInformationGet real-time application information
getParametersGet real-time application parameters
getRootLevelInportsReturns root level inports in application
getSignalsGet real-time application signals
setFileLogDecimationSets decimation value on File Log blocks based on block path and input decimation value
updateASAP2Pack the ASAP2 file into application
updateRootLevelInportDataReplace external input data in real-time application with input data
updateAutoSaveParameterSetOnStopUpdate the auto save parameter set on stop for an application
updateStartupParameterSetUpdate the startup parameter set for an application

Examples

collapse all

Retrieve the ASAP2 file from real-time application.

  1. Create an application object for the real-time application.

    app_obj =  slrealtime.Application("myModel.mldatx");
  2. Retrieve the ASAP2 file from the real-time application.

    extractASAP2(app_obj);

Change waveform data from square wave to sine wave.

  1. Change inport waveform data from a square wave to sine wave.

    waveform = sinewave;
  2. Create an application object.

    app_object = slrealtime.Application('slrt_ex_osc_inport');
  3. Update the inport data.

    updateRootLevelInportData(app_object)
  4. Download the updated inport data to the default target computer.

    tg = slrealtime('TargetPC1');
    load(tg, 'slrt_ex_osc_inport');

You can get and set real-time application options by using the application Options property.

  1. Create an application object.

    my_app = slrealtime.Application('slrt_ex_osc_inport');
  2. View application options by getting the application Options property values.

    my_app.Options.get
    ans = 
    
      struct with fields:
    
                fileLogMaxRuns: 1
                      loglevel: "info"
        overrideBaseRatePeriod: 0
              pollingThreshold: 1.0000e-04
           startupParameterSet: "paramInfo"
                      stoptime: Inf
  3. Change the application stop time value option.

    my_app.Options.set("stoptime",20);

    Note

    You can inadvertently delete existing file logs for an installed real-time application on the target computer if you use the slrealtime.Application function to change the Options for FileLogMaxRuns and then reload the application. To change the number of stored logs without deleting existing logs, load the real-time application and then change the FileLogMaxRuns option by using the start(tg) function.

  4. Save application options to a MATLAB variable. Apply options from the variable to the real-time application by using the load function.

    my_options = my_app.Options.get;
    save("my_options.mat", "my_options");
    load("my_options.mat", "my_options");
    my_app.Options.set(my_options);

You can get real-time application signals and parameters by using the getParameters and getSignals functions.

  1. Create an application object.

    my_app = slrealtime.Application('slrt_ex_param_tuning')
    my_app = 
    
      Application with properties:
    
        ApplicationName: 'slrt_ex_param_tuning'
              ModelName: 'slrt_ex_param_tuning'
               UserData: []
                Options: [1×1 slrealtime.internal.ApplicationOptions]
  2. Get the application Signals values as structures in an array.

    my_sigs = getSignals(my_app)
    my_sigs = 
    
      1×9 struct array with fields:
    
        BlockPath
        PortIndex
        SignalLabel
  3. View application signals as array elements.

    my_sigs(1).BlockPath
    ans =
    
        'slrt_ex_param_tuning/Gain'
  4. Get the application Parameters values as structures in an array.

    my_params = getParameters(my_app)
    my_params = 
    
      1×7 struct array with fields:
    
        BlockPath
        BlockParameterName
  5. View application parameters as array elements.

    my_params(1).BlockParameterName
    ans =
    
        'Gain'

Version History

Introduced in R2020b

expand all