Main Content

Author, Manage, and Execute Simulation-Based Tests of Generated Code

Author, manage, and execute simulation-based tests of the generated code, by using Simulink® Test™ with Simulink PLC Coder™.

  1. If you do not have the plcdemo_simple_subsystem model open, open it. To open the model, enter:

    openExample('plcdemo_simple_subsystem');

  2. Create a signal build test harness for the subsystem. To create a test harness for a subsystem, select the subsystem, right-click, and from the context menu, select Test Harness > Create for <subsystem name>. Set test harness properties through the Create Test Harness dialog box.

  3. Open the PLC Coder app. Click the PLC Code tab.

  4. Click Settings.

  5. In the Configuration Parameters dialog box, on the PLC Code Generation pane, select a target and click the Generate testbench for subsystem check box.

  6. Click OK.

  7. Select the Test Harness Window subsystem, click the PLC Code tab and click Generate PLC Code. The generated code contains multiple test benches from the signal builder. You can run this code in the PLC emulator to make sure it matches your model simulation.

Limitations

  • If you use anything other than a signal builder block in the test harness, you must create a top-level atomic subsystem in the test harness that contains the subsystem under test and the testing blocks (for example, test sequence block) and generate code for this subsystem.

  • Simulink PLC Coder does not support the verify keyword in the test sequence block

  • Simulink PLC Coder supports the duration keyword in the test sequence block but it requires that you run the generated code with the same sample rate as in the Simulink model.