Using Simulink Test with Simulink PLC Coder

You can use Simulink® Test™ with Simulink PLC Coder™ to author, manage, and execute simulation-based tests of the generated code.

  1. If you do not have the plcdemo_simple_subsystem model open, open it now.

  2. Create a signal build test harness for the subsystem as shown. 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 using the Create Test Harness dialog box.

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

  4. Click Settings. The Configuration Parameters dialog box is displayed.

  5. On the PLC Code Generation pane, select a target and enable the Generate testbench for subsystemoption.

  6. Click OK.

  7. Right-click and select Generate code for the subsystem from the Test Harness Window. 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 simulation.


  • 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 both the subsystem under test and the testing blocks (for example, say test sequence block) and generate code for this subsystem.

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

  • Simulink PLC Coder does support duration keyword in the test sequence block but it requires the generate code to be run with the same sample rate as in the Simulink model