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
.L5X file was created using RSLogix™ 5000 IDE and contains contacts and coils representing switches and motor. This
figure shows the ladder structure.
plcladderimportfunction 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 named
MainTask, and finally a Ladder Diagram Program block named
MainProgram. The model imported into Simulink has blocks that implement the functionality of the contacts and coils.
Generate code for the subsystem
generatedFiles = plcgeneratecode('simpleController/simpleController');
PLC code generation successful for 'simpleController/simpleController'. Generated ladder files: plcsrc\simpleController_gen.L5X
You cannot generate structured text code from the Ladder Diagram blocks. The Ladder feature supports only ladder code generation.