Main Content

Import and Verify Structured Text Code

Generate structured text code and test bench from your model. Verify the generated code by importing the generated code and test bench into your target IDE. You can verify that the output of the generated code matches the output of the model simulation by using the test bench data.

Generate, Import, and Verify Structured Text

This example shows how to import and verify your generated code by using the generated test bench:

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

    openExample('plcdemo_simple_subsystem');

  2. Open the PLC Coder app. Click the PLC Code tab > Settings > PLC Code Generation.

  3. Select the Generate testbench for subsystem check box. Click OK.

  4. Click the PLC Code tab. Click Settings > Verify Code in IDE.

  5. In the PLC Code tab, click Generate PLC Code.

When you select Verify Code in IDE, the software:

  1. Generates the code and test bench.

  2. Starts the target IDE.

  3. Creates a project.

  4. Imports the generated code and test bench to the new project in the target IDE.

  5. Runs the generated code on the target IDE to verify it.

If you do not specify that the test bench code must be generated, when you verify the generated code, you see the error Testbench not selected.

For information on:

Troubleshooting: Long Test Bench Code Generation Time

When generating code that has a testbench and the test bench data size exceeds the limit that Simulink® PLC Coder™ can handle, it might result in long code generation times. The test bench data size depends on the number of times the input signal is sampled during simulation. When the simulation time is long or the simulation signals are sampled at a high frequency, the test bench data can be large.

To reduce test bench data size and code generation time, you can:

  • Reduce the duration of the simulation.

  • Increase the simulation step size.

  • If you want to retain the simulation duration and the step size, divide the simulation into multiple parts. For a simulation input signal that have the duration [0, t], divide the input into multiple parts with durations [0, t1], [t1, t2 ], [t2, t3], and so on, where t1 < t2 < t3 < .. < t. Generate test bench code for each part separately and manually import them together to your IDE.

Related Topics