Main Content

Simulink.ModelReference.modifyProtectedModel

Modify existing protected model

Description

example

Simulink.ModelReference.modifyProtectedModel(model) modifies options for an existing protected model created from the specified model. If Name,Value pair arguments are not specified, the modified protected model is updated with default values and supports only simulation.

example

Simulink.ModelReference.modifyProtectedModel(model,Name,Value) uses additional options specified by one or more Name,Value pair arguments. These options are the same options that are provided by the Simulink.ModelReference.protect function. However, these options have additional options to change encryption passwords for read-only view, simulation, and code generation. When you add functionality to the protected model or change encryption passwords, the unprotected model must be available. The software searches for the model on the MATLAB® path. If the model is not found, the software reports an error.

example

[harnessHandle] = Simulink.ModelReference.modifyProtectedModel(model,'Harness',true) creates a harness model for the protected model. It returns the handle of the harnessed model in harnessHandle.

[~ ,neededVars] = Simulink.ModelReference.modifyProtectedModel(model) returns a cell array that includes the names of base workspace variables used by the protected model.

Examples

collapse all

Create a modifiable protected model with support for code generation, then reset it to default values.

Add the password for when a protected model is modified. If you skip this step, you are prompted to set a password when a modifiable protected model is created.

openExample('sldemo_mdlref_counter');
Simulink.ModelReference.ProtectedModel.setPasswordForModify(...
'sldemo_mdlref_counter','password');

Create a modifiable protected model with support for code generation and Web view.

Simulink.ModelReference.protect('sldemo_mdlref_counter','Mode',...
'CodeGeneration','Modifiable',true,'Report',true);

Provide the password to modify the protected model.

Simulink.ModelReference.ProtectedModel.setPasswordForModify(...
'sldemo_mdlref_counter','password');

Modify the model to use default values.

Simulink.ModelReference.modifyProtectedModel(...
'sldemo_mdlref_counter');

The resulting protected model is updated with default values and supports only simulation.

Create a modifiable protected model with support for code generation and Web view, then modify it to remove the Web view support.

Add the password for when a protected model is modified. If you skip this step, you are prompted to set a password when a modifiable protected model is created.

openExample('sldemo_mdlref_counter');
Simulink.ModelReference.ProtectedModel.setPasswordForModify(...
'sldemo_mdlref_counter','password');

Create a modifiable protected model with support for code generation and Web view.

Simulink.ModelReference.protect('sldemo_mdlref_counter','Mode',...
'CodeGeneration','Webview',true,'Modifiable',true,'Report',true);

Provide the password to modify the protected model.

Simulink.ModelReference.ProtectedModel.setPasswordForModify(...
'sldemo_mdlref_counter','password');

Remove support for Web view from the protected model that you created.

Simulink.ModelReference.modifyProtectedModel(...
'sldemo_mdlref_counter', 'Mode', 'CodeGeneration','Report',true);

Change an encryption password for a modifiable protected model.

Add the password for when a protected model is modified. If you skip this step, you are prompted to set a password when a modifiable protected model is created.

openExample('sldemo_mdlref_counter');
Simulink.ModelReference.ProtectedModel.setPasswordForModify(...
'sldemo_mdlref_counter','password');

Add the password that the protected model user must provide to generate code.

Simulink.ModelReference.ProtectedModel.setPasswordForSimulation(...
'sldemo_mdlref_counter','cgpassword');

Create a modifiable protected model with a report and support for code generation with encryption.

Simulink.ModelReference.protect('sldemo_mdlref_counter','Mode',...
'CodeGeneration','Encrypt',true,'Modifiable',true,'Report',true);

Provide the password to modify the protected model.

Simulink.ModelReference.ProtectedModel.setPasswordForModify(...
'sldemo_mdlref_counter','password');

Change the encryption password for simulation.

Simulink.ModelReference.modifyProtectedModel(
'sldemo_mdlref_counter','Mode','CodeGeneration','Encrypt',true,...
'Report',true,'ChangeSimulationPassword',...
{'cgpassword','new_password'});

Add a harness model for an existing protected model.

Add the password for when a protected model is modified. If you skip this step, you are prompted to set a password when a modifiable protected model is created.

openExample('sldemo_mdlref_counter');
Simulink.ModelReference.ProtectedModel.setPasswordForModify(...
'sldemo_mdlref_counter','password');

Create a modifiable protected model with a report and support for code generation with encryption.

Simulink.ModelReference.protect('sldemo_mdlref_counter','Mode',...
'CodeGeneration','Modifiable',true,'Report',true);

Provide the password to modify the protected model.

Simulink.ModelReference.ProtectedModel.setPasswordForModify(...
'sldemo_mdlref_counter','password');

Add a harness model for the protected model.

[harnessHandle] = Simulink.ModelReference.modifyProtectedModel(...
'sldemo_mdlref_counter','Mode','CodeGeneration','Report',true,...
'Harness',true);

Input Arguments

collapse all

Model name, specified as a string or character vector. It contains the name of a model or the path name of a Model block that references the protected model.

Name-Value Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Mode','CodeGeneration','OutputFormat','Binaries','ObfuscateCode',true specifies that obfuscated code be generated for the protected model. It also specifies that only binary files and headers in the generated code be visible to users of the protected model.
General

collapse all

Folder for protected model, specified as a string or character vector.

Example: 'Path','C:\Work'

Option to generate a report, specified as a Boolean value.

To view the report, right-click the protected-model badge icon and select Display Report. Or, call the Simulink.ProtectedModel.open function with the report option.

The report is generated in HTML format. It includes information on the environment, functionality, license requirements, and interface for the protected model.

Example: 'Report',true

Option to generate HDL code, specified as a Boolean value.

This option requires HDL Coder™ license. When you enable this option, make sure that you specify the Mode. You can set this option to true in conjunction with the Mode set to CodeGeneration to enable both C code and HDL code generation support for the protected model.

If you want to enable only simulation and HDL code generation support, but not C code generation, set Mode to HDLCodeGeneration. You do not have to set the hdl option to true.

Example: 'hdl',true

Option to create a harness model, specified as a Boolean value.

Example: 'Harness',true

Option to add a postprocessing function for protected model files, specified as a function handle. The function accepts a Simulink.ModelReference.ProtectedModel.HookInfo object as an input variable. This object provides information on the source code files and other files generated during protected model creation. The object also provides information on exported symbols that you must not modify. Prior to packaging the protected model, the postprocessing function is called.

For a protected model with a top model interface, the Simulink.ModelReference.ProtectedModel.HookInfo object cannot provide information on exported symbols.

Example: 'CustomPostProcessingHook',@(protectedMdlInf)myHook(protectedMdlInf)

Functionality

collapse all

Model protection mode. Specify one of the following values:

  • 'Normal': If the top model is running in 'Normal' mode, the protected model runs as a child of the top model.

  • 'Accelerator': The top model can run in 'Normal', 'Accelerator', or 'Rapid Accelerator' mode.

  • 'CodeGeneration': The top model can run in 'Normal', 'Accelerator', or 'Rapid Accelerator' mode and support code generation.

  • 'HDLCodeGeneration': The top model can run in 'Normal', 'Accelerator', or 'Rapid Accelerator' mode and support HDL code generation.

  • 'ViewOnly': Turns off Simulate and Generate code functionality modes. Turns on the read-only view mode.

Example: 'Mode','Accelerator'

Note

This argument affects the output only when you specify Mode as 'Accelerator' or 'CodeGeneration. When you specify Mode as 'Normal', only a MEX-file is part of the output package.

Protected code visibility. This argument determines what part of the code generated for a protected model is visible to users. Specify one of the following values:

  • 'CompiledBinaries': Only binary files and headers are visible.

  • 'MinimalCode': Includes only the minimal header files required to build the code with the chosen build settings. Code in the build folder is visible. Users can inspect the code in the protected model report and recompile it for their purposes.

  • 'AllReferencedHeaders': Includes header files found on the include path. Code in the build folder is visible. Header files referenced by the code are also visible.

Example: 'OutputFormat','AllReferencedHeaders'

Option to obfuscate generated code, specified as a Boolean value. Applicable only when code generation is enabled for the protected model. Obfuscation is not supported for HDL code generation.

Example: 'ObfuscateCode',true

Option to include a read-only view of protected model, specified as a Boolean value.

To open the Web view of a protected model, use one of the following methods:

  • Right-click the protected-model badge icon and select Show Web view.

  • Use the Simulink.ProtectedModel.open function. For example, to display the Web view for protected model sldemo_mdlref_counter, you can call:

    Simulink.ProtectedModel.open('sldemo_mdlref_counter', 'webview');

  • Double-click the .slxp protected model file in the Current Folder browser.

  • In the Block Parameter dialog box for the protected model, click Open Model.

Example: 'Webview',true

Encryption

collapse all

Option to change the encryption password for simulation, specified as a cell array of two character vectors. The first vector is the old password, the second vector is the new password.

Example: 'ChangeSimulationPassword',{'old_password','new_password'}

Option to change the encryption password for read-only view, specified as a cell array of two character vectors. The first vector is the old password, the second vector is the new password.

Example: 'ChangeViewPassword',{'old_password','new_password'}

Option to change the encryption password for code generation, specified as a cell array of two character vectors. The first vector is the old password, the second vector is the new password.

Example: 'ChangeCodeGenerationPassword',{'old_password','new_password'}

Option to encrypt a protected model, specified as a Boolean value. Applicable when you have specified a password during protection, or by using the following methods:

Example: 'Encrypt',true

Output Arguments

collapse all

Handle of the harness model, returned as a double or 0, depending on the value of Harness.

If Harness is true, the value is the handle of the harness model; otherwise, the value is 0.

Names of base workspace variables used by the protected model, returned as a cell array.

The cell array can also include variables that the protected model does not use.

Introduced in R2014b