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 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 Non-Top Level function.
Open Simulink PLC Coder.
Select the Subsystem1
block.
Click Settings. Navigate to PLC Code Generation > Identifiers. Select the check box next to Keep top level ssMethod name same as non-top level.
Click OK.
Repeat steps 2 through 4 for SubSystem2
, SubSystem3
, and TopSystem
.
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>
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>