This example shows how to import a Ladder Diagram from an .L5X
file
created by using Rockwell Automation® IDEs such as RSLogix™ 9 5000 and Studio 5000 into the Simulink® environment. The import operation is performed by using the plcimportladder
function.
The figure shows a Ladder Diagram with a simple timer. The Ladder Diagram consists of four
rungs with contacts (Switch_A
, Light1
,
Motor_timer.DN
), coils (Light1
,
Light2
, Motor
), and TON
timer
function.
The simple_timer.L5X
file was created by using the RSLogix 5000 IDE. A snippet of the .L5X
file is
shown.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <RSLogix5000Content SchemaRevision="1.0" SoftwareRevision="30.00" TargetName="simple_timer" TargetType="Controller" ContainsContext="false" Owner="Arun Mathew Iype, MathWorks" ExportDate="Mon Nov 12 16:35:28 2018" ExportOptions="NoRawData L5KData DecoratedData ForceProtectedEncoding AllProjDocTrans"> <Controller Use="Target" Name="simple_timer" ProcessorType="Emulate 5570" MajorRev="30" MinorRev="11" TimeSlice="20" ShareUnusedTimeSlice="1" ProjectCreationDate="Mon Nov 12 16:33:36 2018" LastModifiedDate="Mon Nov 12 16:33:43 2018" SFCExecutionControl="CurrentActive" SFCRestartPosition="MostRecent" SFCLastScan="DontScan" ProjectSN="16#0000_0000" MatchProjectToController="false" CanUseRPIFromProducer="false" InhibitAutomaticFirmwareUpdate="0" PassThroughConfiguration="EnabledWithAppend" DownloadProjectDocumentationAndExtendedProperties="true" DownloadProjectCustomProperties="true" ReportMinorOverflow="false"> <RedundancyInfo Enabled="false" KeepTestEditsOnSwitchOver="false" IOMemoryPadPercentage="90" DataTablePadPercentage="50"/> <Security Code="0" ChangesToDetect="16#ffff_ffff_ffff_ffff"/> <SafetyInfo/> <DataTypes/> <Modules> <Module Name="Local" CatalogNumber="Emulate 5570" Vendor="1" ProductType="14" ProductCode="53" Major="30" Minor="11" ParentModule="Local" ParentModPortId="1" Inhibited="false" MajorFault="true"> <EKey State="ExactMatch"/> <Ports> <Port Id="1" Address="0" Type="ICP" Upstream="false"> <Bus Size="10"/> </Port> </Ports> </Module> </Modules> <AddOnInstructionDefinitions/> <Tags/> <Programs> <Program Name="MainProgram" TestEdits="false" MainRoutineName="MainRoutine" Disabled="false" UseAsFolder="false"> ... <Tags>
Before importing the .L5X
file into Simulink :
Verify the Ladder Diagram file is a valid .L5X
file. The file can be
verified by compiling it in Rockwell Automation IDE.
If the file is valid, copy the .L5X
file into a folder with read and
write permissions. You can also create a separate folder to store all the imported files
along with the original Ladder Diagram .L5X
file.
Use the plcimportladder
function to import the ladder into Simulink. For this example, the program Name
of the ladder is
MainProgram
and the MainRoutineName
is
MainRoutine
.
>> plcimportladder('simple_timer.L5X')
The Ladder Diagram is imported into the pwd\simple_timer.slx
Simulink model. The state information of the ladder elements is stored in the data store
memory and updated by the model during simulation. The
plcout\simple_timer_value.m
file gets called during the pre-load stage of
the Simulink model. This file sets the timer initial values in Motor_timer
data store memory.
The simple_timer.slx
Simulink model consists of a Ladder Diagram Controller as the top unit.
This controller has a Main Task
and Controller Tags
.
The Main Task
consists of a Main Program
.
The Main Program
contains the Simulink implementation of the simple_timer.L5X
Ladder Diagram. The
ladder rung executes from top to bottom and left to right.
You can use the Signal Builder block to create test inputs for
Switch_A
and verify the operation of the imported ladder. You can also
generate a PLC Ladder Diagram code or a C code for the top-level subsystem. If you want to edit
the imported ladder, the Simulink blocks are in the template Ladder Diagram Library
. To open the
library, enter:
plcladderlib
If your Ladder Diagram has comments associated with the rung, these comments are also
imported to Simulink. In the Simulink environment, the comments are connected to the respective rung. For example, the
Ladder Diagram for the simple timer has a comment Switch ON Delay
. After
importing the ladder diagram to Simulink, the comment is also imported as seen in Rung
3
of the imported Simulink model.
Similarly, when you generate Ladder Diagram code from a Simulink model containing a rung comment, the comment is also generated in the
(L5X)
ladder file. If your Simulink model has multiple comments associated with the rung, in the generated Ladder
Diagram, these comments are merged into a single comment with each individual comment appearing
in a separate line.
If you have an L5X
file containing an AOI with mixed ordered arguments,
this order is preserved during import and export of the files.
plccleartypes
| plcgeneratecode
| plcgeneraterunnertb
| plcimportladder
| plcladderlib
| plcladderoption
| plcloadtypes