Main Content

plcgeneratecode

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

Description

example

generatedfiles= plcgeneratecode(system)在模型中为指定原子子系统生成结构文本或梯形图。

  • Structured Text is generated for the specified atomic subsystem in a model. Argumentsystemis the fully qualified path name of the atomic subsystem.generatedfilesis 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. Argumentsystem是Simulink中顶级组织单位的完全限定路径名称金宝app®model. Thesystemshould either be aPLC Controllerblock,Ladder Diagram Function (AOI)block or anAOI Runnerblock.generatedfilesis 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 theplcladderimportfunction to import the ladder into Simulink.

[mdlName,mdlLib,busScript] = plcimportladder(“simpleController.L5X','OpenModel','On')

The imported model contains aPLC Controllerblock namedsimpleController, followed by aTaskblock named主要任务and finally aLadder Diagram Programblock 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

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