Modify existing protected model
Simulink.ModelReference.modifyProtectedModel(
modifies
options for an existing protected model created from the specified model
)model
.
If Name,Value
pair arguments are not specified,
the modified protected model is updated with default values and supports
only simulation.
Simulink.ModelReference.modifyProtectedModel(
uses
additional options specified by one or more model
,Name,Value
)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.
[
creates
a harness model for the protected model. It returns the handle of
the harnessed model in harnessHandle
] = Simulink.ModelReference.modifyProtectedModel(model
,'Harness
',true)harnessHandle
.
[~ ,
returns
a cell array that includes the names of base workspace variables used
by the protected model.neededVars
] = Simulink.ModelReference.modifyProtectedModel(model
)
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.
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.
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.
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.
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);
model
— Model nameModel 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.
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
.
'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.'Path'
— Folder for protected modelFolder for protected model, specified as a string or character vector.
Example: 'Path','C:\Work'
'Report'
— Option to generate a reportOption 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
'hdl'
— Option to generate HDL codeOption 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
'Harness'
— Option to create a harness modelOption to create a harness model, specified as a Boolean value.
Example: 'Harness',true
'CustomPostProcessingHook'
— Option to add postprocessing function for protected model filesOption 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)
'Mode'
— Model protection mode'Normal'
(default) | 'Accelerator'
| 'CodeGeneration'
| 'HDLCodeGeneration'
| 'ViewOnly'
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'
'OutputFormat'
— Protected code visibility'CompiledBinaries'
(default) | 'MinimalCode'
| 'AllReferencedHeaders'
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'
'ObfuscateCode'
— Option to obfuscate generated codeOption 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
'Webview'
— Option to include a Web viewOption 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
'ChangeSimulationPassword'
— Option to change the encryption password for simulationOption 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'}
'ChangeViewPassword'
— Option to change the encryption password for read-only viewOption 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'}
'ChangeCodeGenerationPassword'
— Option to change the encryption password for code generationOption 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'}
'Encrypt'
— Option to encrypt protected modelOption 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:
Password for read-only view of model: Simulink.ModelReference.ProtectedModel.setPasswordForView
Password for simulation: Simulink.ModelReference.ProtectedModel.setPasswordForSimulation
Password for code generation: Simulink.ModelReference.ProtectedModel.setPasswordForCodeGeneration
Password for HDL code generation: Simulink.ModelReference.ProtectedModel.setPasswordForHDLCodeGeneration
Example: 'Encrypt',true
harnessHandle
— Handle of the harness modelHandle 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
.
neededVars
— Names of base workspace variablesNames 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.
Simulink.ModelReference.protect
| Simulink.ModelReference.ProtectedModel.setPasswordForModify