Simulink.ProtectedModel.Callback class

Package: Simulink.ProtectedModel
Superclasses:

Represents callback code that executes in response to protected model events

Description

For a protected model functionality, the Simulink.ProtectedModel.Callback object specifies code to execute in response to an event. The callback code can be a character vector of MATLAB® commands or a MATLAB script. The object includes:

  • The code to execute for the callback.

  • The event that triggers the callback.

  • The protected model functionality that the event applies to.

  • The option to override the protected model build.

When you create a protected model, to specify callbacks, call the Simulink.ModelReference.protect function with the 'Callbacks' option. The value of this option is a cell array of Simulink.ProtectedModel.Callback objects.

Construction

example

pmCallback = Simulink.ProtectedModel.Callback(event,functionality,callbackText) creates a callback object for a specific protected model functionality and event. The callbackText specifies MATLAB commands to execute for the callback.

example

pmCallback = Simulink.ProtectedModel.Callback(event,functionality,callbackFile) creates a callback object for a specific protected model functionality and event. The callbackFile specifies a MATLAB script to execute for the callback. The script must be on the MATLAB path.

Input Arguments

expand all

Callback trigger event. Specify one of the following values:

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

  • 'Build': Callback code is executed before build. Valid only for 'CODEGEN' functionality.

Protected model functionality that the event applies to. Specify one of the following 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 only for 'CODEGEN' functionality.

If you do not specify a functionality, the default behavior is 'AUTO'.

MATLAB commands to execute in response to an event, specified as a string or character vector.

MATLAB script to execute in response to an event, specified as a string or character vector. Script must be on the MATLAB path.

Properties

expand all

Protected model functionality that the event applies to. Value is one of the following:

  • '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 only for 'CODEGEN' functionality.

If you do not specify a functionality, the default behavior is 'AUTO'.

MATLAB script to execute in response to an event, specified as a string or character vector. Script must be on the MATLAB path.

Example: 'pmCallback.m'

MATLAB commands to execute in response to an event, specified as a string or character vector.

Example: 'A = [15 150];disp(A)'

Callback trigger event. Value is one of the following:

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

  • 'Build': Callback code is executed before build. Valid only for 'CODEGEN' functionality.

Option to override the protected model build process, specified as a Boolean value. Applies only to a callback object that you define for a 'Build' event for 'CODEGEN' functionality. You set this option using the setOverrideBuild method.

Methods

setOverrideBuildSpecify option to override protected model build

Copy Semantics

Handle. To learn how handle classes affect copy operations, see Copying Objects.

Examples

Create Protected Model Using a Callback

Create a callback object with a character vector of MATLAB commands for the callback code. Specify the object when you create a protected model.

pmCallback = Simulink.ProtectedModel.Callback('PreAccess',...
'SIM','disp(''Hello world!'')')
Simulink.ModelReference.protect('sldemo_mdlref_counter',...
'Callbacks',{pmCallback})
sim('sldemo_mdlref_basic')

For each instance of the protected model reference in the top model, the output is listed.

Hello world!
Hello world!
Hello world!

Create Protected Model With a Callback Script

Create a callback object with a MATLAB script for the callback code. Specify the object when you create a protected model.

pmCallback = Simulink.ProtectedModel.Callback('Build',...
'CODEGEN','pm_callback.m')
Simulink.ModelReference.protect('sldemo_mdlref_counter',...
'Mode', 'CodeGeneration','Callbacks',{pmCallback})
rtwbuild('sldemo_mdlref_basic')

Before the protected model build process begins, code in pm_callback.m executes.

Introduced in R2016a