Create Protected Models with Multiple Targets
You can create a protected model that supports multiple code generation targets. This example shows how to use command-line functions to create a protected model that supports code generation for GRT and ERT targets.
Load a model and save a local copy. This model is configured for a GRT target.
openExample('sldemo_mdlref_counter'); save_system('sldemo_mdlref_counter','mdlref_counter.slx');
Add a required password for modifying a protected model. If you do not add a password, you are prompted to set a password when you create a modifiable, protected model.
Simulink.ModelReference.ProtectedModel.setPasswordForModify(... 'mdlref_counter','password');
Create a modifiable, protected model with support for code generation.
Simulink.ModelReference.protect('mdlref_counter','Mode',... 'CodeGeneration', 'Modifiable',true, 'Report',true);
Get a list of targets that the protected model supports.
st = Simulink.ProtectedModel.getSupportedTargets('mdlref_counter')
st = 'grt' 'sim'
Configure the unprotected model to support an ERT target.
set_param('mdlref_counter', 'SystemTargetFile', 'ert.tlc'); save_system('mdlref_counter');
Add support to the protected model for the ERT target. You are prompted for the modification password.
Simulink.ProtectedModel.addTarget('mdlref_counter');
Verify that the list of supported targets now includes the ERT target.
st = Simulink.ProtectedModel.getSupportedTargets('mdlref_counter')
st = 'ert' 'grt' 'sim'