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 and select Analysis > Test Harness > Create for <subsystem name>. Set test harness properties using the Create Test Harness dialog box.

  3. Right-click the Subsystem block and select PLC Code > Options. The Configuration Parameters dialog box is displayed.

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

  5. Click Apply.

  6. 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.

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 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