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.
PLC Coder™ software generates Structured Text code and places it in
If you do not have the
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
ReusableSubsystem string in the code).
Examine the generated Structured Text code. The code defines
FUNCTION_BLOCK S1 once.
Look for two instance variables that correspond to the two instances declared
inside the parent
i0_S1: S1 and
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
ssMethodType do not use the output variables of the
FUNCTION_BLOCK. Therefore, the generated Structured Text
SS_INITIALIZE does not contain assignment statements
for the outputs
This optimization is applicable only to IEC 61131-3 compatible targets.