Main Content

Simulink.ProtectedModel.CallbackInfo

Protected model information for use in callbacks

Description

A Simulink.ProtectedModel.CallbackInfo object contains information about a protected model that you can use in the code executed for a callback.

Creation

Description

example

Simulink.ProtectedModel.getCallbackInfo(ModelName,Event,Functionality) creates a Simulink.ProtectedModel.CallbackInfo object for the callback that applies to the protected model for the event and functionality that you specify.

Properties

expand all

Code interface that the protected model generates, specified as 'Top model' or 'Model reference'.

Event that triggered the callback, specified as one of these values:

  • 'PreAccess': Callback code executed before simulation, build, or read-only viewing.

  • 'Build': Callback code executed before build. This option is valid only for the 'CODEGEN' functionality.

Protected model functionality that the event applies to, specified as one of these values:

  • 'CODEGEN': Code generation.

  • 'SIM': Simulation.

  • 'VIEW': Read-only web view.

  • 'AUTO': If the event is 'PreAccess', the callback executes for each functionality. If the event is 'Build', the callback executes for only 'CODEGEN' functionality.

Protected model name, specified as a character vector or string scalar.

Example: 'myProtectedModel.slxp'

Names of all models and submodels in the protected model container, specified as a cell array of character vectors.

Current target identifier for the protected model, specified as a character vector. This property is available for only code generation callbacks.

Example: 'ert'

Object Functions

getBuildInfoForModelBuild information object for specified model

Examples

collapse all

  1. On the MATLAB® path, create a callback script pm_callback.m that contains this code:

    s1 = 'Simulating protected model: ';
    cbinfobj = Simulink.ProtectedModel.getCallbackInfo(...
    'sldemo_mdlref_counter','PreAccess','SIM');
    disp([s1 cbinfobj.ModelName])

    The script uses the Simulink.ProtectedModel.CallbackInfo object to display the name of the protected model.

  2. Create a callback object that uses the script for the callback code. Protect the model sldemo_mdlref_counter and specify the callback object.

    pmCallback = Simulink.ProtectedModel.Callback('PreAccess'...
    ,'SIM', 'pm_callback.m')
    Simulink.ModelReference.protect('sldemo_mdlref_counter',...
    'Callbacks',{pmCallback})
    
  3. Simulate the protected model. When each instance of the protected model reference in the top model is simulated, the output from the callback is listed.

    sim('sldemo_mdlref_basic')
    Simulating protected model: sldemo_mdlref_counter
    Simulating protected model: sldemo_mdlref_counter
    Simulating protected model: sldemo_mdlref_counter
Introduced in R2016a