Generate structured text code for different components of your model.
Open the model by using the following command:
open_system('mSystemIntegration');
To autogenerate structured text code with the same ssMethod
type for every component of your model for external code integration later on, use Keep Top-Level ssMethod Name the Same as the Non-Top Level Name. For more information, see Keep Top-Level ssmethod Name the Same as the Non-Top Level Name function.
Open the Simulink PLC Coder app. For more information, see Simulink PLC Coder.
Select the TopSystem
block.
Click Settings. Navigate to PLC Code Generation > Identifiers. In the Identifier Names
box enter Subsystem1,Subsystem2,Subsystem3
.
Click OK.
Open the Simulink PLC Coder app. For more information, see Simulink PLC Coder.
Select the Subsystem1
block.
Click Settings. Navigate to PLC Code Generation > Identifiers. Select the Keep top level ssMethod name same as non-top level check box.
Click OK.
Repeat steps 2 through 4 for SubSystem2
, SubSystem3
, and TopSystem
.
To generate code for the individual subsystem use the plcgenerate code function:
plcgeneratecode('mSystemIntegration/TopSystem/SubSystem1');
plcgeneratecode('mSystemIntegration/TopSystem/SubSystem2');
plcgeneratecode('mSystemIntegration/TopSystem/SubSystem3');
To generate code for the integrated model:
plcgeneratecode('mSystemIntegration/TopSystem');