Main Content

Verify Generated Ladder Diagram Code

The following example demonstrates how to import a simple Ladder Diagram from an .L5X file (simpleXIC.L5X) into the Simulink® environment and generate test bench code for it. The Ladder Diagram .L5X file was created using RSLogix™ 5000 IDE and contains an AOI named simpleXIC with contact and coil representing a switch and a light. The following is a snapshot of the ladder structure.

  1. Use the plcladderimport function to import the ladder into Simulink.

    [mdlName,mdlLib,busScript] = plcimportladder('simpleXIC.L5X',...
  2. The imported model contains an AOI Runner block named simpleXIC_runner, followed by a Ladder Diagram Function (AOI) block named simpleXIC.

  3. Add Signal Builder input block, Scope and output ports as shown.

  4. Modify the Signal Builder input to mimic a switch operation as shown.

  5. Generate test-bench for the Ladder Diagram model.

    Tbcode = plcgeneraterunnertb('simpleXIC_runner/simpleXIC_runner')
    Tbcode =
      1×1 cell array

    If the test-bench code generation is successful, a test-bench file simpleXIC_runner.L5X is created. The generated AOI test bench file can be verified on Rockwell Automation® IDE.

If you have created the Ladder Diagram model in Simulink and are generating Ladder Diagram (L5X) code, you can also use the Generate testbench for subsystem option available on the PLC Code Generation pane in the Configuration Parameters dialog box to generate test bench code along with ladder code. When the selected subsystem is ladder AOI Runner block and test bench option is on, the generated code will include test bench, selected AOI, as well as dependent AOI and UDT types.

See Also

| | | | | |

Related Topics