Mastering PLC Programming
Read it now on the O’Reilly learning platform with a 10-day free trial.
O’Reilly members get unlimited access to books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.
Book description
Learn PLC programming from the software perspective to understand advanced concepts such as OOP and HMI development and design reusable, portable, and robust code
Purchase of the print or Kindle book includes a free PDF eBook
Key Features
- Take a deep dive into object-oriented PLC programming to gain hands-on knowledge
- Explore software engineering concepts such as SDLC, debugging, and SOLID programming
- Get a thorough grasp on HMI development to build various HMI projects
Book Description
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.
What you will learn
- Find out how to write PLC programs using advanced programming techniques
- Explore OOP concepts for PLC programming
- Delve into software engineering topics such as libraries and SOLID programming
- Explore HMIs, HMI controls, HMI layouts, and alarms
- Create an HMI project and attach it to a PLC in CODESYS
- Gain hands-on experience by building simulated PLC and HMI projects
Who this book is for
This book is for automaton programmers with a background in software engineering topics such as object-oriented programming and general software engineering knowledge. Automation engineers, software engineers, electrical engineers, PLC technicians, hobbyists, and upper-level university students with an interest in automation or robotics will also find this book useful and interesting. Anyone with a basic knowledge of PLCs can benefit from reading this book.
Show and hide more
Table of contents Product information
Table of contents
- Contributors
- About the author
- About the reviewers
- Who this book is for
- What this book covers
- To get the most out of this book
- Download the example code files
- Download the color images
- Conventions used
- Get in touch
- Share Your Thoughts
- Download a free PDF copy of this book
- Technical requirements
- Software engineering for PLCs
- Understanding the IEC 61131-3 standard
- What does the IEC 61131-3 standardize?
- Programming a PLC – The five IEC languages
- Creating the program
- Technical requirements
- Understanding error handling
- Variables
- The main program
- The division by 0 error
- Checking for 0 code
- TRY-CATCH blocks
- FINALLY statements
- Identifying and handling errors
- Representing PLC memory
- General syntax for pointers
- The ADR operator
- Dereferencing pointers
- Handling invalid pointers
- Declaring a reference variable
- Example program
- Checking for invalid references
- Self-documenting code
- Code to variables
- Code commenting
- Variables for the state machine
- Exploring state machine logic
- Technical requirements
- What is debugging?
- Types of bugs
- Testing versus debugging
- Breaking down the debugging process
- Print debugging
- The CODESYS debugger tool
- Forcing variables
- Case 4 – a while loop
- Technical requirements
- Auto declaring variables
- Understanding constants
- Investigating arrays
- Initialized arrays
- Multidimensional arrays
- Creating a GVL
- Declaring a struct
- Persistent variable list
- Technical requirements
- What is modular code?
- Why use modular code?
- Exploring functions
- What goes into a function?
- Creating a function
- The PLC_PRG file
- The RETURN statement
- Named parameters
- Default arguments
- Technical requirements
- What is OOP?
- Why use OOP?
- The four pillars – A preview
- Adding a method
- Adding a property
- Getter method
- Setter method
- THIS keyword
- Recursion in action
- Technical requirements
- Understanding access specifiers
- Calculation program
- Encapsulation versus abstraction
- Inheritance
- Polymorphism
- When to use composition
- Composition in practice
- Technical requirements
- Investigating libraries
- Why do we need libraries?
- Libraries versus frameworks
- Distribution
- Third-party libraries
- Installing a library
- Rule 1 – Keep it simple, stupid (KISS)
- Rule 2 – Abstraction and encapsulation
- Rule 3 – Patterns make for perfection
- Rule 4 – Documentation
- Requirements
- Implementation
- Requirements
- Implementation
- Technical requirements
- Understanding the SDLC
- Why care about the SDLC?
- How is the SDLC implemented?
- Requirements/planning
- Design
- Build
- Test
- Deployment
- Maintenance
- Gathering requirements for the library
- Designing the library
- Building the library
- Testing the library
- Deploying the library
- Maintaining the library
- Technical requirements
- Introducing SOLID programming
- Benefits of SOLID programming
- The governing principles of SOLID programming
- The single-responsibility principle
- The open-closed principle
- The Liskov substitution principle
- The interface segregation principle
- The Dependency inversion principle
- Technical requirements
- Understanding HMIs
- Why create and use an HMI?
- How are HMIs created?
- Programming languages to develop HMIs
- What should an HMI do?
- Technical requirements
- Exploring common HMI controls
- Flip switches
- Push switches
- Buttons
- LEDs
- Potentiometers
- Sliders
- Spinners
- Measurement controls
- Histogram
- Text field
- Control properties
- Requirements for the HMI
- Design of the HMI
- Building the HMI
- Technical requirements
- The importance of colors
- Backgrounds
- Red, yellow, and green
- Control colors
- Labeling colors
- Blinking a component
- Animation
- Creating visualizations screens
- Changing the default screen
- Navigating between screens
- Technical requirements
- What are alarms?
- When should you use an alarm?
- What should an alarm say?
- Alarm groups
- Setting up an alarm banner
- Setting up an alarm table
- Requirements
- Design/implementation of the HMI
- Technical requirements
- Project overview
- Getting the requirements
- HMI design
- HMI implementation
- LED variables
- Acknowledgment variable
- Spinner variables/setup
- Gauge variable/setup
- Alarm table variables/configuration
- PLC_PRG file
- Alarms function block
- Door function block
- Oven function block
- Testing the door lock
- Testing the gauge
- Technical requirements
- What are computer networks?
- Network topology
- TCP/IP
- UDP
- Modbus
- Profibus
- Profinet
- EtherCAT
- DeviceNet
- Protocol conversion
- Other communication topics to explore
- Chapter 1: Software Engineering for PLCs
- Chapter 2: Advanced Structured Text — Programming a PLC in Easy-to-Read English
- Chapter 3: Debugging — Making Your Code Work
- Chapter 4: Complex Variable Declaration — Using Variables to Their Fullest
- Chapter 5: Functions — Making Code Modular and Maintainable
- Chapter 6: OOP — Reducing, Reusing, and Recycling Code
- Chapter 7: OOP — The Power of Objects
- Chapter 8: Libraries — Write Once, Use Anywhere
- Chapter 9: The SDLC — Navigating the SDLC to Create Great Code
- Chapter 10: Advanced Coding — Using SOLID to Make Solid Code
- Chapter 11: HMIs — UIs for PLCs
- Chapter 12: Industrial Controls — User Inputs and Outputs
- Chapter 13: Layouts — Making HMIs User Friendly
- Chapter 14: Alarms — Avoiding Catastrophic Issues with Alarms
- Chapter 15: Putting It All Together — The Final Project
- Chapter 16: Distributed Control Systems, PLCs, and Networking
- Why subscribe?
- Packt is searching for authors like you
- Share Your Thoughts
- Download a free PDF copy of this book
Show and hide more
Product information
- Title: Mastering PLC Programming
- Author(s): M. T. White
- Release date: March 2023
- Publisher(s): Packt Publishing
- ISBN: 9781804612880