Main Content

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.

  1. 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');
  2. 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');
  3. Create a modifiable, protected model with support for code generation.

    Simulink.ModelReference.protect('mdlref_counter','Mode',...
    'CodeGeneration', 'Modifiable',true, 'Report',true);
  4. Get a list of targets that the protected model supports.

     st = Simulink.ProtectedModel.getSupportedTargets('mdlref_counter')
    st = 
    
        'grt'    'sim'
  5. Configure the unprotected model to support an ERT target.

     set_param('mdlref_counter', 'SystemTargetFile', 'ert.tlc'); 
     save_system('mdlref_counter');
  6. Add support to the protected model for the ERT target. You are prompted for the modification password.

     Simulink.ProtectedModel.addTarget('mdlref_counter');
  7. Verify that the list of supported targets now includes the ERT target.

     st = Simulink.ProtectedModel.getSupportedTargets('mdlref_counter')
    st = 
    
        'ert'    'grt'    'sim'

Related Topics