Book Image

Mastering PLC Programming

By : Mason White
Book Image

Mastering PLC Programming

By: Mason White

Overview of this book

Object-oriented programming (OOP) is a new feature of PLC programming that has taken the automation world by storm. This book provides you with the necessary skills to succeed in the modern automation programming environment. The book is designed in a way to take you through advanced topics such as OOP design, SOLID programming, the software development lifecycle (SDLC), library design, HMI development, general software engineering practices, and more. To hone your programming skills, each chapter has a simulated real-world project that’ll enable you to apply the skills you’ve learned. In all, this book not only covers complex PLC programming topics, but it also removes the financial barrier that comes with most books as all examples utilize free software. This means that to follow along, you DO NOT need to purchase any PLC hardware or software. By the end of this PLC book, you will have what it takes to create long-lasting codebases for any modern automation project.
Table of Contents (25 chapters)
1
Part 1 – An Introduction to Advanced PLC Programming
6
Part 2 – Modularity and Objects
10
Part 3 – Software Engineering for PLCs
14
Part 4 – HMIs and Alarms
19
Part 5 – Final Project and Thoughts

Software engineering for PLCs

Software engineering is more than just writing programs. Software engineering is the art of effectively solving problems. A major problem with the current industrial programming mindset is that software is often treated almost as a second-class citizen to the hardware. In other words, PLC software is treated as a complement to hardware. More often than not, the software is treated as a throwaway component. It is not uncommon for software practices to be thrown to the wind in automation programming. As such, code\bases that can be easily modified and last for years will often have to be discarded long before they should. Many books and training courses treat PLC software in this way, which, in turn, continues a cycle of treating PLC software as a complement to PLC hardware. Overall, this is a flawed philosophy. Software is every bit as important as (and to certain extents, more important than) hardware. In all, when properly written programs are implemented, machines will be more easily modifiable and correctable. Software can then be transferred to other machines, which will minimize coding defects and yield successful manufacturing operations.

For many non-traditional software developers, a very bad philosophy has taken root. Many of these developers feel that a working solution is a good solution. However, imagine that you’re a car mechanic. Would it be wise to weld the hood shut so that every time you needed an oil change, the hood would have to be cut off with a plasma cutter? Technically, the hood would function the same way as it would on your vehicle now. It would still protect the elements of your engine but at the cost of needing to cut it open for routine maintenance. Though welding your hood onto your vehicle would work, it would not be a wise engineering choice. Software development should be approached in the same way. Just because a solution works does not make it a good solution.

How should a software engineer approach a problem? The answer to that question is the same way any other type of engineer would approach a problem: by first understanding the issue and then developing an effective solution for it. When software engineers approach a problem, they need to try to implement a solution that solves the problem in a way that is simple, efficient, and as easy to maintain as possible. In much the same way as an electrical or mechanical engineer would design their product, a software developer will need to do the same. A software engineer will have to learn to develop solutions that fulfill the requirements of the original problem as well as concoct a solution that can be easily modified in the future. A software engineer must have the following in mind when developing software:

  • Does the solution solve the problem?
  • Is the solution overcomplicated?
  • Can the solution be easily modified if changes are needed?
  • Can the solution be verified to ensure it works (can it be easily tested)?

Often, this mentality is lost on PLC programmers. Many PLC programmers do not see themselves as software engineers; however, it must be understood that the moment a keyboard or mouse is touched with the intent of programming something to solve a problem, the programmer becomes a software engineer. When code is developed with this mentality, the same mentality that electrical engineers would use to implement their design, a codebase is created that is clean, easy to maintain, and easy to upgrade, and it will pass the test of time and allow for adaptation for the future.

A key feature of modern software and a key feature of a quality software developer is reusability. Quality code can be used for many different projects without rewriting it. In the automation realm, this can be a bit challenging, as every PLC producer has their own take on PLC development software. However, many PLCs follow what is known as the IEC 61131-3 standard, which provides some uniformity across PLC platforms.