You can use Simulink® Test™ with Simulink PLC Coder™ to author, manage, and execute simulation-based tests of the generated code.
If you do not have the
plcdemo_simple_subsystem model open, open
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
Harness dialog box.
Right-click the Subsystem block and select PLC Code > Options. The Configuration Parameters dialog box is displayed.
On the PLC Code Generation pane, select a target and enable the Generate testbench for subsystemoption.
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.
PLC Coder does not yet support
verify keyword in the test
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