Advantages of Re-Usable Code
Recently I’ve seen some good discussions on PLCs (Programmable Logic Controllers) vs. PACs (Programmable Automation Controllers), and it got me thinking about what really differentiates the two. Some have said that it is having a more powerful processor, or more capable software. Others have said that it is the ability to fully utilize all of the IEC 61131 programming languages and capabilities.
In the US, many programmers base their knowledge and abilities on their experience with Allen-Bradley’s products. After all, probably 70% or more of the installed base in US manufacturing consists of A-B PLCs. If so, the ControlLogix family was a huge jump in the capability of PLCs; among other improvements over the SLC and PLC5 families are the fact that it is tag-based, allows the use of UDTs, and has Add-On Instructions (AOIs). Tags could also be made local to each program, allowing them to be duplicated for re-use.
But all of those capabilities except for being tag-based already existed years before that on other platforms. IEC 61131 has existed since 1993 or so, and other PLCs leveraged that early on. Siemens for instance has had User Defined Types or Structures since the S7 platform came out, and local variables could also be defined within Functions and Function Blocks. As a matter of fact, Siemens’ Function Blocks (FBs) are very similar to Allen-Bradley’s AOIs, except that the retentive values have to be included in a separate data block.
In my opinion, 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 several important 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 I mean by this 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. 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”, etc. UDTs don’t require tag based systems, but they do require advanced use of symbols. This is one reason the Allen-Bradley SLC and Micrologix systems really don’t allow re-usable code, while the S7 does, despite both being 1990s -era systems.
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.
Whether your favorite platform uses subroutines with local variables or customizable instructions, reusable code is a critical part of creating powerful programs quickly! I am quite familiar with how Allen-Bradley and Siemens accomplish this, but I would love to hear how some other platforms allow for reusable code and what their methods are. Leave a comment here or send me an e-mail, I’d especially like to hear from users of CodeSys, Beckhoff, GE, Mitsubishi, Omron and Automation Direct!