Main Content

plcgeneratecode

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

Description

example

generatedfiles= plcgeneratecode(system) generates Structure Text or Ladder Diagram for the specified atomic subsystem in a model.

  • Structured Text is generated for the specified atomic subsystem in a model. Argument system is the fully qualified path name of the atomic subsystem.generatedfiles is a cell array of the generated file names. You must first load or start the model.

  • Ladder Diagram (L5X) file is generated for the specified system in the model. Argument system is the fully qualified path name of the top organizational unit in the Simulink® model. The system should either be a PLC Controller block, Ladder Diagram Function (AOI) block or an AOI Runner block. generatedfiles is a cell array of the generated file names. You must first load or start the Simulink model.

Examples

collapse all

Open or load the model containing the subsystem.

plcdemo_simple_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 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, 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.

Introduced in R2010a