Encapsulating your data into custom Data Structures will allow you to Dominate (maybe not the world, but at least your PLC)
I'm going to conclude my series on the IEC 61131-3 standard by examining the benefits of Data Structures. (If you missed my other posts, you can check out the previous part 1, part 2, part 3)
Before we dive into Data Structures, let's review basic data types.
Every PLC supports a certain group of standard data types. The list typically includes the following:
- Bit (0 or 1)
- Byte (0 to 255)
- Word (0 to 65,535)
- Integer (−32,768 to +32,767)
- Double Word (0 to +4,294,967,295)
- Double Int (−2,147,483,648 to +2,147,483,647)
- Real (4 byte floating point)
- Time (encoding depends on the PLC)
- String (depends on PLC, but typically the max length 255 characters)
- Arrays (any of the above types grouped into an array)
These are the basics, but many PLCs support more types.
Now that we have reviewed basic types, we can discuss discuss Data Structures or User Defined Types (UDT). Data Structures are custom data types that are constructed by grouping (or clustering) native data types.
You can handle pretty much anything with these native types, but there are many times where you can group these native types into a cluster or Data Structure. This concept allows you to better organize and maintain the data in your program. In a recent project that we completed, we had created a reusable Function Block to control a motor. We needed to send a set of commands and parameters into this block in order to control the motor. In order to better manage this functionality we encapsulated the native types into a User Defined Type that could be passed in as a single variable.
This is how the function block would look if we were NOT using custom Data Structures. Each individual data type is separately fed into the block.
This is OK, however if you have another function block that is controlling this one, it will have to have each one of its outputs separately tied to this block's inputs. Here is how that would look:
Again, this is OK, but in our case we had hundreds of motors on a large production line. We did not want to manually create all of these links for each separate value. So we combined them into a Data Structure!
Now all of those commands are encapsulated into one variable (our custom Data Structure). They can be easily passed from one place to another in one big chunk.
There are many benefits to organizing your variables into Data Structures:
- Reduces programming errors
- Passing data in large groups reduces the chances of making errors that would be associated with passing several individual variables.
- Eliminates redundant programming
- Fewer lines of code required to pass data from one place to another
- Enforces consistency
- Define the Data Structure once and then use it throughout your program.
- Facilitates quick program changes
- Since the Data Structure is defined in one place, you can easily make changes to the Structure that automatically propagate throughout the program.
- In our case we could make a change to our motor control structure and each of the hundred instances function blocks was automatically updated. This was a huge time saver.
This concludes my series on the IEC 61131-3 Programming Standard (at least for now). I truly hope you enjoyed the information. Please feel free to comment and let me know your thoughts.
Learn more about DMC's PLC programming services.