Advantages of reusable code for PLCs
Reusable code for programmable logic controllers (PLCs) provide users with flexibility and allow structures to be built that can be exported from one application to another.
Many programmers base their knowledge and abilities on their experience with Allen-Bradley products from Rockwell Automation since much of the installed base in manufacturing consists of A-B programmable logic controllers (PLCs). Rockwell Automation’s ControlLogix family was a huge jump in PLC capabilities with enhancements such as being tag-based, allowing the use of user-defined data types (UDTs), and add-on instructions (AOIs). Tags could also be made local to each program, allowing them to be duplicated for re-use.
All of those capabilities, except for being tag-based, already existed years before that on other platforms. IEC 61131 for programming languages has existed since 1993 or so, and other PLCs leveraged that early on. One of the most important differences between the older, register-only based systems and the more modern ones is the ability to build re-usable code blocks. Platforms that support this must have these three features:
1. Local vs. global variables. Re-usable code must have variables that apply to each instance of the code; ideally only formatting the data once for the original code. What this means is that a list of tags or symbols should not have to be re-named for each instance or call. For instance, duplicating a subroutine several times and iterating the addresses inside of it, though it saves time, isn’t really re-usable code.
2. User-defined data types (UDTs). Creating UDTs allows structures to be built that can be exported from one application to another. They allow components to be described using generic terms such as "Speed," "Start," "Reject," and others. UDTs don’t require tag based systems, but they do require advanced use of symbols.
3. Protectable self-contained blocks. It is important that the code be contained in a block that allows variables to be passed in and out, and also protected so that users can’t change a specific instance of it. This requires a password or software key.
These are just some of the requirements. Other features like being able to write code in other IEC-compliant PLC languages such as structured text also help make platforms much more powerful and "Rapid Code Development" friendly.
Regardless of whether the platform uses subroutines with local variables or customizable instructions, reusable code is a critical part of creating powerful programs quickly. Many platforms allow reusable code, and each has its own unique methods.
Frank Lamb is the founder of Automation Consulting Services Inc. This article originally appeared on the Automation Primer blog. Automation Primer is a CFE Media content partner. Edited by Chris Vavra, production editor, Control Engineering, CFE Media, firstname.lastname@example.org.
See additional stories from Automation Primer linked below.
Original content can be found at automationprimer.com.