PLC Code Generation Basics

Generate Structured Text

Apps

Simulink PLC CoderGenerate structured text and ladder diagram code from Simulink models, Stateflow charts, and MATLAB functions

Functions

plccoderdemosProduct examples
plccoderprefManage user preferences
plcgeneratecodeGenerate Structured Text or Ladder Diagram (L5X) for the atomic subsystem
plcopenconfigsetOpen Configuration Parameters dialog box for subsystem

Examples and How To

Generate and Examine Structured Text Code

Get started with Structured Text code generation from a simple Simulink® model.

Integrate Generated Code with Custom Code

Call the generated function block with different values of ssMethodType argument for subsystem initialization and computation steps.

Specify Custom Names for Generated Files

Override the default naming convention, which uses the model name for the generated Structured Text code file.

Propagate Block Descriptions to Code Comments

View block descriptions from your model as comments in generated Structured Text code.

Generate Structured Text Code For Simulink Data Dictionary Defined Model Parameters

Configure model to generate structured text code for Simulink.Parameter objects within the model Simulink data dictionary (SLDD).

Structured Text Code Generation Support for Enumerated Data Type Conversion

This example shows how to autogenerate structured text code for the enum to integer conversion model

Use PLC_RemoveSSStep for Distributed Code Generation

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.

Structured Text Code Generation for Subsystem Reference Blocks

This example shows how to autogenerate structured text code for subsystem reference blocks.

Concepts

Files Generated with Simulink PLC Coder

Look up the location of files for manually importing the generated Structured Text code to your IDE.

Generated Code Structure for Simple Simulink Subsystems

Map model objects in your Simulink subsystem to constructs in generated Structured Text code.

Generated Code Structure for Reusable Subsystems

Generate Structured Text code from a reusable subsystem and identify the code reuse.

Generated Code Structure for Triggered Subsystems

Generate Structured Text code from a triggered subsystem and identify the trigger event-based execution in the generated code.

Generated Code Structure for Stateflow Charts

Generate Structured Text code from a Stateflow® Chart and identify event-based transitions or absolute time temporal logic in the generated code.

Generated Code Structure for MATLAB Function Block

Generate Structured Text code from a MATLAB Function block and identify the MATLAB® function content in the generated code.

Generated Code Structure for Multirate Models

Generate Structured Text code from a multirate model and identify the multiple execution rates in the generated code.

Generated Code Structure for Subsystem Mask Parameters

Generate Structured Text code from a masked subsystem and identify the mask parameters in the generated code.

Generate Structured Text Code with Logging Instrumentation

Workflow for generating Structured Text code with logging instrumentation.

Global Tunable Parameter Initialization for PC WORX

Learn how global tunable parameters appear in code generated for the PC WORX™ IDE.

Featured Examples