plcgeneratecode - Generate structured text or ladder diagram (L5X) for the atomic

        subsystem - MATLAB ([original](https://in.mathworks.com/help/plccoder/ref/plcgeneratecode.html)) ([raw](?raw))

Main Content

Generate structured text or ladder diagram (L5X) for the atomic subsystem

Syntax

Description

[generatedfiles](#mw%5Fe67270b6-8a66-4d86-9b4b-2b69507b8207)= plcgeneratecode([system](#mw%5Fe16a402b-75b6-446e-9e33-1312f66a165b)) generates Structure Text or Ladder Diagram for the specified atomic subsystem in a model.

example

Examples

collapse all

Open or load the model containing the subsystem.

Generate code for the subsystem, plcdemo_simple_subsystem/SimpleSubsystem.

generatedFiles = plcgeneratecode('plcdemo_simple_subsystem/SimpleSubsystem');

The following example demonstrates 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 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.

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 namedsimpleController, 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,simpleController/simpleController.

generatedFiles = plcgeneratecode('simpleController/simpleController');

PLC code generation successful for 'simpleController/simpleController'.

Generated ladder files: plcsrc\simpleController_gen.L5X

Input Arguments

collapse all

For Structured Text, system specifies the relative or absolute path to the atomic subsystem in the Simulink model.

For Ladder Diagram, system specifies the relative or absolute path to the Simulink model, imported from the Ladder L5X file or a manually created model.

Output Arguments

collapse all

Specifies the name of the generated code and testbench files.

Version History

Introduced in R2010a