Main Content

Generated Code Structure for Simple Simulink 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.

  1. If you do not have the plcdemo_simple_subsystem.exp file open, open it in the MATLAB® editor. In the folder that contains the file, type:

    edit plcdemo_simple_subsystem.exp

    A file like the following is displayed.

    The following figure illustrates the mapping of the generated code to Structured Text components for a simple Simulink subsystem. The Simulink subsystem corresponds to the Structured Text function block, Subsystem.

    Note

    The coder maps alias data types to the base data type in the generated code.

  2. Inspect this code as you ordinarily do for PLC code. Check the generated code.

Note

The Simulink model for plcdemo_simple_subsystem does not contain signal names at the input or output of the SimpleSubsystem block. So the generated code has the port names U and Y as the input and output variable names of the FUNCTION_BLOCK. However, even if your model does contain signal names, coder only uses port names in the generated code.