Structs in WinCC OA

Introduction to Structs

Structs, short for structures, are user-defined data types in WinCC OA that allow you to create complex variables that can hold multiple data members. Each data member within a struct can have its own data type, such as strings, integers, booleans, etc.

Declaration and Usage

To declare a struct, you use the struct keyword followed by the struct's name and its members:


    struct TestDetails {
        string name;
        bool StartStatus;
        bool EndStatus;
        int progress;
        string color;
        string status;
    }
    

Advantages of Structs

Structs provide several benefits, such as:

  • Memory efficiency: Structs are stack-allocated and have a smaller memory footprint compared to classes.
  • Performance: Accessing struct members is generally faster due to their memory locality.
  • Value semantics: Structs are value types, meaning they are copied when assigned, leading to predictable behavior.

Methods in Structs

Structs can contain methods, just like classes. These methods can perform various operations and computations based on the struct's data members.

Default Access Modifier

Unlike classes, the members of a struct default to public access. This means that the members can be accessed from anywhere within the scope of the instance.

Checking if a Data Type is a Struct

In WinCC OA, you can use the isDpTypeStruct() function to check if a data point type is a struct type. This function returns true if the data point type is a struct.

Conclusion

Structs are a powerful feature in WinCC OA that allow you to define custom data types with their own members and methods. They are particularly useful for scenarios where you need to bundle related data together in a lightweight and efficient manner.

Create Your Own Struct