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.
- 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. Thesystem
should either be aPLC 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
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
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
Specifies the name of the generated code and testbench files.
Version History
Introduced in R2010a