🔹This course is from 2023 and is now free. You can still access it ad free at https://liambee.me
if you become a member or purchase the course.
🔹Downloadable content for this course is available here for free:
https://liambee.me/codesys-structured...
In this lesson we look at how to create structures in Codesys. Structures are often referred to as UDTs or DUTs. A UDT is a user defined type and a DUT is a data unit type, but both terms describe the same concept. The goal of this lesson is to help you understand how to build these structures and how they become usable inside your project.
We begin by creating a new DUT in a blank Codesys project. Once the editor opens, we define our structure between the STRUCT and END_STRUCT keywords, which is consistent across many PLC platforms. Inside this structure we add variables such as on, off, temperature, and even arrays. This forms the blueprint for our new data type.
After the structure is defined, we look at how to instantiate it. A structure cannot be used directly until it has been given memory through an instance. We create a global variable list and add instances such as motor1 and motor2. These now become accessible containers that hold all variables defined inside the DUT.
We then test this inside a program by accessing motor1 and motor2 in the logic editor. You can immediately see every Boolean and element defined in the structure and use them in your logic just like standard variables. The lesson also shows how structures can be grouped under a common container, allowing you to have multiple types for different equipment such as soft start pumps, VSD pumps, or dosing pumps, all neatly organised.
A key benefit shown in this lesson is automatic expansion. When we update the structure to include a new element such as fault, every instance of the structure gains that element instantly. There are no manual changes required in the individual instances, and your logic can immediately reference the new variable. This becomes even more powerful later in the course when structures are combined with function blocks.
By the end of the lesson, you will understand how to create a structure, how to instantiate it, and how these instances become reusable building blocks throughout your Codesys project.
#AlwaysLearning #Automation #Codesys #PLC #HMI