Main Content

Deploy Structured Text

Using Simulink PLC Coder, you can generate structured text and test bench code, and then import the generated code into the target IDE.

Learning Objectives

In this tutorial you learn how to:

  • Open the plcdemo_simple_subsystem model and prepare the model for code generation.

  • Verify the code that you generated.

  • Automatically or manually import your generated code into your target IDE.

Prerequisites

  • Simulink® PLC Coder™

  • Target IDE folder location (for automatic import).

Workflow

  1. Open the plcdemo_simple_subsystem model. To open the model, enter:

    openExample('plcdemo_simple_subsystem');

  2. Open the model settings and set Solver Selection to Fixed-step and Solver to discrete(no continuous states).

  3. If your target IDE is in the PLC IDEs for Importing Code Automatically , see Generate and Automatically Import Structured Text Code. Otherwise , see Importing Generated Structured Text Code Manually

Importing Generated Structured Text Code Manually

If your target IDE does not automatically import generated code:

  1. Right-click the Subsystem block and select PLC Code > Options.

    The Configuration Parameters dialog box is displayed.

  2. On the PLC Code Generation pane, select an option from the Target IDE list, for example, 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 plccoderpref function.

  3. Click Apply.

  4. Click Generate code.

    This button:

    • Generates Structured Text code (same as the PLC Code > Generate Code for Subsystem option)

    • Stores generated code in model_name.exp (for example, plcdemo_simple_subsystem.exp)

    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 by Simulink PLC Coder.

  5. To import generated code into your target IDE import the generated files manually into your target IDE.