You must already have set up your environment and Simulink® model to use the Simulink PLC Coder™ software to generate Structured Text code. If you have not yet done so, see Prepare Model for Structured Text Generation.
If you do not have the
open, open it now.
Open the PLC Coder app. Click PLC Code tab.
The Configuration Parameters dialog box is displayed.
On the PLC Code Generation pane,
select an option from the Target IDE list, for
3S CoDeSys 2.3.
The default Target IDE list displays the
full set of supported IDEs. To see a reduced subset of the target
IDEs supported by Simulink
PLC Coder, disable the option Show
full target list. To customize this list, use the
Click Generate PLC Code.
Generates Structured Text code (same as the PLC Code > Generate Code for Subsystem option)
Stores generated code in
When code generation is complete, a View diagnostics hyperlink appears at the bottom of the model window. Click this hyperlink to open the Diagnostic Viewer window.
This window has links that you can click to open the associated files. For more information, see Files Generated with Simulink PLC Coder.
You can generate Structured Text code for a subsystem in the Command Window with the
plcgeneratecode function. You must have already configured the parameters for
the model or, alternatively, you can use the default settings.
For example, to generate code from the
Open the Configuration Parameters dialog box using
Select a target IDE.
Configure the subsystem as described in Prepare Model for Structured Text Generation.
Generate code for the subsystem:
generatedfiles = plcgeneratecode('plcdemo_simple_subsystem/SimpleSubsystem')
plcgeneratecode for code generation, all diagnostic
messages are printed to the MATLAB® command window.
After generating the code, you can view it in the MATLAB Editor. For a description of how the generated code for the Simulink components map to Structured Text components, see PLC Code Generation Basics. In addition, note the following:
Matrix data types: The coder converts matrix data types to single-dimensional vectors (column-major) in the generated Structured Text.
Generated code header: If your model has author names, creation dates, and model descriptions, the generated code contains these items in the header comments. The header also lists fundamental sample times for the model and the subsystem block for which you generate code.
Code comments: You can choose to propagate block descriptions to comments in generated code. See Propagate Block Descriptions to Code Comments.
The figure illustrates generated code for the CoDeSys Version 2.3 PLC IDE. Generated code for other platforms, such as Rockwell Automation® RSLogix™ 5000, is in XML or other format and looks different.
If you are confident that the generated Structured Text is good, optionally change your workflow to automatically generate and import code to the target IDE. For more information, see Import Structured Text Code Automatically.