Main Content

Prevent External Variable Initialization for Distributed Code Generation

Generate structured text code for different components of your model.

Open model

Open the model by using the following command:

open_system('External_Var_Distributed_Codegen');

Configure Model Components for Distributed Code Generation

To autogenerate structured text code by preventing initialization statements for externally defined variables for external code integration later on, use remove Initialization Statements for Externally Defined State Variables. for more information, see Remove Initialization Statements for Externally Defined State Variables.

Mark Externally Defined Variables

  1. Open the Simulink PLC Coder app. For more information, see Simulink PLC Coder.

  2. Select the Subsystem block.

  3. Click Settings. Navigate to PLC Code Generation > Identifiers. In the Identifier Names box enter child1,child2,DSExportedGlobal.

  4. Click OK.

Code Generation

  1. Open the Simulink PLC Coder app. For more information, see Simulink PLC Coder.

  2. Select the Subsystem block.

  3. Click Settings. Navigate to PLC Code Generation > Interface. Select the Remove Initialization Statements for externally defined state variables check box.

  4. Click OK.

Generate Code for the Subsystem

To generate code for the individual subsystem use the plcgenerate code function:

plcgeneratecode('External_Var_Distributed_Codegen/Subsystem');

Related Topics

Generated Code Structure for PLC_PreventExternalVarInitialization.

Related Topics