Mastering PLC Programming

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

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

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

  1. Contributors
    1. About the author
    2. About the reviewers
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Share Your Thoughts
    9. Download a free PDF copy of this book
    1. Technical requirements
    2. Software engineering for PLCs
    3. Understanding the IEC 61131-3 standard
      1. What does the IEC 61131-3 standardize?
      2. Programming a PLC – The five IEC languages
      1. Creating the program
      1. Technical requirements
      2. Understanding error handling
        1. Variables
        2. The main program
        3. The division by 0 error
        4. Checking for 0 code
        5. TRY-CATCH blocks
        6. FINALLY statements
        7. Identifying and handling errors
        1. Representing PLC memory
        2. General syntax for pointers
        3. The ADR operator
        4. Dereferencing pointers
        5. Handling invalid pointers
        1. Declaring a reference variable
        2. Example program
        3. Checking for invalid references
        1. Self-documenting code
        2. Code to variables
        3. Code commenting
        1. Variables for the state machine
        2. Exploring state machine logic
        1. Technical requirements
        2. What is debugging?
          1. Types of bugs
          2. Testing versus debugging
          3. Breaking down the debugging process
          1. Print debugging
          2. The CODESYS debugger tool
          3. Forcing variables
          1. Case 4 – a while loop
          1. Technical requirements
          2. Auto declaring variables
          3. Understanding constants
          4. Investigating arrays
            1. Initialized arrays
            2. Multidimensional arrays
            1. Creating a GVL
            1. Declaring a struct
            1. Persistent variable list
            1. Technical requirements
            2. What is modular code?
            3. Why use modular code?
            4. Exploring functions
              1. What goes into a function?
              2. Creating a function
              3. The PLC_PRG file
              1. The RETURN statement
              1. Named parameters
              2. Default arguments
              1. Technical requirements
              2. What is OOP?
              3. Why use OOP?
                1. The four pillars – A preview
                1. Adding a method
                1. Adding a property
                1. Getter method
                2. Setter method
                1. THIS keyword
                2. Recursion in action
                1. Technical requirements
                2. Understanding access specifiers
                  1. Calculation program
                  1. Encapsulation versus abstraction
                  2. Inheritance
                  3. Polymorphism
                  1. When to use composition
                  2. Composition in practice
                  1. Technical requirements
                  2. Investigating libraries
                    1. Why do we need libraries?
                    2. Libraries versus frameworks
                    3. Distribution
                    4. Third-party libraries
                    5. Installing a library
                    1. Rule 1 – Keep it simple, stupid (KISS)
                    2. Rule 2 – Abstraction and encapsulation
                    3. Rule 3 – Patterns make for perfection
                    4. Rule 4 – Documentation
                    1. Requirements
                    2. Implementation
                    1. Requirements
                    2. Implementation
                    1. Technical requirements
                    2. Understanding the SDLC
                      1. Why care about the SDLC?
                      2. How is the SDLC implemented?
                      1. Requirements/planning
                      2. Design
                      3. Build
                      4. Test
                      5. Deployment
                      6. Maintenance
                      1. Gathering requirements for the library
                      2. Designing the library
                      3. Building the library
                      4. Testing the library
                      5. Deploying the library
                      6. Maintaining the library
                      1. Technical requirements
                      2. Introducing SOLID programming
                      3. Benefits of SOLID programming
                      4. The governing principles of SOLID programming
                        1. The single-responsibility principle
                        2. The open-closed principle
                        3. The Liskov substitution principle
                        4. The interface segregation principle
                        5. The Dependency inversion principle
                        1. Technical requirements
                        2. Understanding HMIs
                          1. Why create and use an HMI?
                          2. How are HMIs created?
                          3. Programming languages to develop HMIs
                          4. What should an HMI do?
                          1. Technical requirements
                          2. Exploring common HMI controls
                            1. Flip switches
                            2. Push switches
                            3. Buttons
                            4. LEDs
                            5. Potentiometers
                            6. Sliders
                            7. Spinners
                            8. Measurement controls
                            9. Histogram
                            10. Text field
                            11. Control properties
                            1. Requirements for the HMI
                            2. Design of the HMI
                            3. Building the HMI
                            1. Technical requirements
                            2. The importance of colors
                              1. Backgrounds
                              2. Red, yellow, and green
                              3. Control colors
                              4. Labeling colors
                              1. Blinking a component
                              2. Animation
                              1. Creating visualizations screens
                              2. Changing the default screen
                              3. Navigating between screens
                              1. Technical requirements
                              2. What are alarms?
                                1. When should you use an alarm?
                                2. What should an alarm say?
                                1. Alarm groups
                                1. Setting up an alarm banner
                                2. Setting up an alarm table
                                1. Requirements
                                2. Design/implementation of the HMI
                                1. Technical requirements
                                2. Project overview
                                3. Getting the requirements
                                4. HMI design
                                5. HMI implementation
                                  1. LED variables
                                  2. Acknowledgment variable
                                  3. Spinner variables/setup
                                  4. Gauge variable/setup
                                  5. Alarm table variables/configuration
                                  1. PLC_PRG file
                                  2. Alarms function block
                                  3. Door function block
                                  4. Oven function block
                                  1. Testing the door lock
                                  2. Testing the gauge
                                  1. Technical requirements
                                  2. What are computer networks?
                                    1. Network topology
                                    1. TCP/IP
                                    2. UDP
                                    1. Modbus
                                    2. Profibus
                                    3. Profinet
                                    4. EtherCAT
                                    5. DeviceNet
                                    6. Protocol conversion
                                    7. Other communication topics to explore
                                    1. Chapter 1: Software Engineering for PLCs
                                    2. Chapter 2: Advanced Structured Text — Programming a PLC in Easy-to-Read English
                                    3. Chapter 3: Debugging — Making Your Code Work
                                    4. Chapter 4: Complex Variable Declaration — Using Variables to Their Fullest
                                    5. Chapter 5: Functions — Making Code Modular and Maintainable
                                    6. Chapter 6: OOP — Reducing, Reusing, and Recycling Code
                                    7. Chapter 7: OOP — The Power of Objects
                                    8. Chapter 8: Libraries — Write Once, Use Anywhere
                                    9. Chapter 9: The SDLC — Navigating the SDLC to Create Great Code
                                    10. Chapter 10: Advanced Coding — Using SOLID to Make Solid Code
                                    11. Chapter 11: HMIs — UIs for PLCs
                                    12. Chapter 12: Industrial Controls — User Inputs and Outputs
                                    13. Chapter 13: Layouts — Making HMIs User Friendly
                                    14. Chapter 14: Alarms — Avoiding Catastrophic Issues with Alarms
                                    15. Chapter 15: Putting It All Together — The Final Project
                                    16. Chapter 16: Distributed Control Systems, PLCs, and Networking
                                    1. Why subscribe?
                                    1. Packt is searching for authors like you
                                    2. Share Your Thoughts
                                    3. 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