Verify Generated Ladder Diagram Code
This example shows 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. This figure shows 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 namedsimpleXIC
.Add the Signal Builder input block, Scope, and output ports as shown.
Modify the Signal Builder input to mimic a switch operation.
Generate a 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. You can verify the generated AOI test bench file on the 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 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 a the ladder AOI Runner block and the test bench option is on, the generated code includes test bench, selected AOI, and dependent AOI and user define tag (UDT) types.
See Also
plcimportladder
| plcgeneraterunnertb
| plcgeneratecode
| plcladderlib
| plcladderoption
| plcloadtypes
| plccleartypes