Import L5X Ladder Files into Simulink

This example shows how to import a Ladder Diagram from an .L5X file created using Rockwell Automation® IDEs such as RSLogix™9 5000 and Studio 5000 into the Simulink® environment. The import operation is performed using the plcimportladder function.

Description of the Ladder Diagram

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 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" 
SFCRestartPosition="MostRecent" SFCLastScan="DontScan" 
MatchProjectToController="false" CanUseRPIFromProducer="false" 
InhibitAutomaticFirmwareUpdate="0" PassThroughConfiguration="EnabledWithAppend" 
<RedundancyInfo Enabled="false" KeepTestEditsOnSwitchOver="false" 
<Security Code="0" ChangesToDetect="16#ffff_ffff_ffff_ffff"/>
<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"/>
<Port Id="1" Address="0" Type="ICP" Upstream="false">
<Bus Size="10"/>
<Program Name="MainProgram" TestEdits="false" MainRoutineName="MainRoutine" 
Disabled="false" UseAsFolder="false">

Import Ladder Diagram

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 directory 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:



  • When importing an .L5X file that contains a continuous task, the imported Simulink model has a sample time of -1. For periodic tasks, the sample time is the value specified in the .L5X file. Event tasks are not supported.

  • Simulink PLC Coder™ may not follow the same initialization order specified in the Prescan mode. You must not read data from variables that are initialized by the Prescan mode as this will lead to different behavior in simulation of the model when compared to execution in the IDE. The following instructions are affected by this limitation; OTE, ONS, OSF, OSR, CTD, CTU, TON, TOF, RTO, JSR, AOI, and FBC

  • If you Ladder Diagram implementation has multiple AOI or subroutine instances with the same name, the software does not check if these instances refer to the same implementation. It is recommended to use different names if these structures contain different functionality.

See Also

| | | | | |

Related Topics