Generating Ladder Diagram Code from Simulink
The following example demonstrates how to import a simple Ladder Diagram
.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. The
following is a snapshot of 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
MainTaskand 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.