Generated Code Structure for Reusable Subsystems
This topic assumes that you have generated Structured Text code from a Simulink® model. If you have not yet done so, see Generate Structured Text from the Model Window.
The example in this topic shows generated code for the CoDeSys Version 2.3 IDE. Generated code for other IDE platforms looks different.
Open the PLC Coder app.
Click Generate PLC Code.
The Simulink PLC Coder™ software generates Structured Text code and places it in
If you do not have the
plcdemo_reusable_subsystem.expfile open, open it in the MATLAB® editor.
The following figure illustrates the mapping of the generated code to Structured Text components for a reusable Simulink subsystem. This graphic contains a copy of the hierarchical subsystem, ReusableSubsystem. This subsystem contains two identical subsystems, S1 and S2. This configuration enables code reuse between the two instances (look for the
ReusableSubsystemstring in the code).
Examine the generated Structured Text code. The code defines
Look for two instance variables that correspond to the two instances declared inside the parent
i1_S1: S1). The code invokes these two instances separately by passing in different inputs. The code invokes the outputs per the Simulink execution semantics.
For IEC 61131-3 compatible targets, the non-step and the output
ssMethodTypedo not use the output variables of the
FUNCTION_BLOCK. Therefore, the generated Structured Text code for
SS_INITIALIZEdoes not contain assignment statements for the outputs
This optimization is applicable only to IEC 61131-3 compatible targets.