Use PLC_RemoveSSStep for Distributed Code Generation

This example shows how to generate structured text code for different components of your model, and then allow external integration by keeping ssMethod case names the same.

Open model

Open the model by using the following command:

open_system('mSystemIntegration');

Configure Model Components for Distributed Code Generation

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 Non-Top Level function.

Code Generation

  1. Open Simulink PLC Coder.

  2. Select the Subsystem1 block.

  3. Click Settings. Navigate to PLC Code Generation > Identifiers. Select the check box next to Keep top level ssMethod name same as non-top level.

  4. Click OK.

  5. Repeat steps 2 through 4 for SubSystem2, SubSystem3, and TopSystem.

Generate Code for the Subsystem

To generate code for the individual subsystem use, plcgeneratecode function:

plcgeneratecode('mSystemIntegration/TopSystem/SubSystem1');
plcgeneratecode('mSystemIntegration/TopSystem/SubSystem2');
plcgeneratecode('mSystemIntegration/TopSystem/SubSystem3');
### Generating PLC code for 'mSystemIntegration/TopSystem/SubSystem1'.
### Using <a href="matlab:configset.showParameterGroup('mSystemIntegration', { 'PLC Code Generation' } )">model settings</a> from 'mSystemIntegration' for PLC code generation parameters.
### Gathering test vectors for PLC testbench.
### Begin code generation for IDE <a href="matlab:configset.showParameterGroup('mSystemIntegration', { 'PLC Code Generation' } )">codesys23</a>.
### Emit PLC code to file.
### Creating PLC code generation report <a href="matlab:web('/tmp/BR2020ad_1302590_239645/publish_examples0/tp6583e4b1/ex14753967/codesys23_plcsrc/html/mSystemIntegration/mSystemIntegration_codegen_rpt.html')">mSystemIntegration_codegen_rpt.html</a>.
### PLC code generation successful for 'mSystemIntegration/TopSystem/SubSystem1'.
### Generated files:
<a href="matlab: edit('codesys23_plcsrc/SubSystem1.exp')">codesys23_plcsrc/SubSystem1.exp</a>
### Generating PLC code for 'mSystemIntegration/TopSystem/SubSystem2'.
### Using <a href="matlab:configset.showParameterGroup('mSystemIntegration', { 'PLC Code Generation' } )">model settings</a> from 'mSystemIntegration' for PLC code generation parameters.
### Gathering test vectors for PLC testbench.
### Begin code generation for IDE <a href="matlab:configset.showParameterGroup('mSystemIntegration', { 'PLC Code Generation' } )">codesys23</a>.
### Emit PLC code to file.
### Creating PLC code generation report <a href="matlab:web('/tmp/BR2020ad_1302590_239645/publish_examples0/tp6583e4b1/ex14753967/codesys23_plcsrc/html/mSystemIntegration/mSystemIntegration_codegen_rpt.html')">mSystemIntegration_codegen_rpt.html</a>.
### PLC code generation successful for 'mSystemIntegration/TopSystem/SubSystem2'.
### Generated files:
<a href="matlab: edit('codesys23_plcsrc/SubSystem2.exp')">codesys23_plcsrc/SubSystem2.exp</a>
### Generating PLC code for 'mSystemIntegration/TopSystem/SubSystem3'.
### Using <a href="matlab:configset.showParameterGroup('mSystemIntegration', { 'PLC Code Generation' } )">model settings</a> from 'mSystemIntegration' for PLC code generation parameters.
### Gathering test vectors for PLC testbench.
### Begin code generation for IDE <a href="matlab:configset.showParameterGroup('mSystemIntegration', { 'PLC Code Generation' } )">codesys23</a>.
### Emit PLC code to file.
### Creating PLC code generation report <a href="matlab:web('/tmp/BR2020ad_1302590_239645/publish_examples0/tp6583e4b1/ex14753967/codesys23_plcsrc/html/mSystemIntegration/mSystemIntegration_codegen_rpt.html')">mSystemIntegration_codegen_rpt.html</a>.
### PLC code generation successful for 'mSystemIntegration/TopSystem/SubSystem3'.
### Generated files:
<a href="matlab: edit('codesys23_plcsrc/SubSystem3.exp')">codesys23_plcsrc/SubSystem3.exp</a>

Generate Code for the Integrated Model

To generate code for the integrated model:

plcgeneratecode('mSystemIntegration/TopSystem');
### Generating PLC code for 'mSystemIntegration/TopSystem'.
### Using <a href="matlab:configset.showParameterGroup('mSystemIntegration', { 'PLC Code Generation' } )">model settings</a> from 'mSystemIntegration' for PLC code generation parameters.
### Gathering test vectors for PLC testbench.
### Begin code generation for IDE <a href="matlab:configset.showParameterGroup('mSystemIntegration', { 'PLC Code Generation' } )">codesys23</a>.
### Emit PLC code to file.
### Creating PLC code generation report <a href="matlab:web('/tmp/BR2020ad_1302590_239645/publish_examples0/tp6583e4b1/ex14753967/codesys23_plcsrc/html/mSystemIntegration/mSystemIntegration_codegen_rpt.html')">mSystemIntegration_codegen_rpt.html</a>.
### PLC code generation successful for 'mSystemIntegration/TopSystem'.
### Generated files:
<a href="matlab: edit('codesys23_plcsrc/mSystemIntegration.exp')">codesys23_plcsrc/mSystemIntegration.exp</a>