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.
Use the plcladderimport
function to import the ladder into Simulink.
[mdlName,mdlLib,busScript] = plcimportladder('simpleXIC.L5X',... 'OpenModel','On','TopAOI','simpleXIC')
The imported model contains an AOI Runner block named
simpleXIC_runner
, followed by a Ladder Diagram Function
(AOI) block named simpleXIC
.
Add Signal Builder input block, Scope and output ports as shown.
Modify the Signal Builder input to mimic a switch operation as shown.
Generate test-bench for the Ladder Diagram model.
Tbcode = plcgeneraterunnertb('simpleXIC_runner/simpleXIC_runner')
Tbcode = 1×1 cell array {'C:\runnerTB\simpleXIC_runner.L5X'}
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.
plccleartypes
| plcgeneratecode
| plcgeneraterunnertb
| plcimportladder
| plcladderlib
| plcladderoption
| plcloadtypes