Generating Ladder Diagram Code from Simulink
This example shows how to import a simple Ladder Diagram from an
.L5X
file (simpleController.L5X
) into the Simulink® environment, and then generate Ladder Diagram (L5X) from the imported model. The
Ladder Diagram .L5X
file was created using RSLogix™ 5000 IDE and contains contacts and coils representing switches and motor. This
figure shows the ladder structure.
Use the
plcladderimport
function to import the ladder into Simulink.[mdlName,mdlLib,busScript] = plcimportladder('simpleController.L5X','OpenModel','On')
The imported model contains a PLC Controller block named
simpleController
, followed by a Task block namedMainTask
, and finally a Ladder Diagram Program block namedMainProgram
. The model imported into Simulink has blocks that implement the functionality of the contacts and coils.Generate code for the subsystem
simpleController/simpleController
.generatedFiles = plcgeneratecode('simpleController/simpleController');
PLC code generation successful for 'simpleController/simpleController'. Generated ladder files: plcsrc\simpleController_gen.L5X
Note
You cannot generate structured text code from the Ladder Diagram blocks. The Ladder feature supports only ladder code generation.
See Also
plcimportladder
| plcgeneraterunnertb
| plcgeneratecode
| plcladderlib
| plcladderoption
| plcloadtypes
| plccleartypes