Using Arrays and Structures in Huichuan PLC Programming

In Huichuan PLC programming, variables often include arrays and structures. Today, I will share the usage of both. After reading, you will surely feel a sense of familiarity.

Array Variables

When defining custom variables in Huichuan PLC programming, arrays are frequently used, with the data type being ARRAY.

First, open the variable table, enter a variable name, set the variable type and data length, and click confirm to define an array variable, as shown in the figure below:

Using Arrays and Structures in Huichuan PLC Programming

Clicking the “+” sign next to the variable name expands the detailed information of the sub-variables of the array, allowing you to assign initial values and comments to each sub-variable.

Using Arrays and Structures in Huichuan PLC Programming

Numeric type variables can also be used in arrays, which similarly have data register functionality.

Using Arrays and Structures in Huichuan PLC Programming

When using arrays in programming instructions, it is important to input the array index. The first element of the array is indexed as 0, which is consistent with the bit sequence number of the soft components. In the instructions, if the array index is not input, it will start accessing from the first element; if an index is provided, it will start accessing from the element indicated by the index.

Using Arrays and Structures in Huichuan PLC Programming

As shown in the figure above: since no index is specified, this instruction indicates that the four INT type data in the array DATE are assigned 0.

Using Arrays and Structures in Huichuan PLC Programming

In the figure above: the array specifies the index DATE[2], thus indicating that DATE[2]-DATE[3] is assigned 0.

If it is the ALM array defined above, then each BOOL type sub-variable can represent an alarm code.

Structures

When defining variables, if a structure variable needs to be defined, the data structure of the structure must be defined in advance.

Similarly, under global variables – click “Structure” to select to create a new data structure, enter the structure name, thus defining the structure. Then, different variables can be defined in the variable table. As shown in the figure below:

Using Arrays and Structures in Huichuan PLC Programming

It can also be associated with the variable table. Once the structure is created, when we create a new variable in the variable table, we can select “Structure” which is our self-defined structure. As shown in the figure below:

Using Arrays and Structures in Huichuan PLC Programming

In the variable table, when a new structure variable is created, expanding it will show sub-elements with the same names as in the structure.

Additionally, the structures defined in the variable table can also be batch associated with actual addresses, achieving data storage and access. As shown in the figure below:

Using Arrays and Structures in Huichuan PLC Programming

At this point, we may wonder what the difference and relationship between structures and variables are.

First, a structure does not just define one data type, but can combine multiple variables into a complex data type. In contrast, the variables in the variable table are relatively independent.

Using Arrays and Structures in Huichuan PLC Programming

Relevance:

Variable Encapsulation: A structure can encapsulate multiple variables (such asintegers,booleans,strings, etc.) into a whole, for example, combining device status, control commands, and other attributes into a structure variable.

Address Binding: Structure variables can be bound tosoft component addresses (such asD registers,M components), achieving data storage and access.

Batch Operations: Through structures, variable addresses can be batch bound, reducing manual configuration, for example, quickly mapping variables inrecipe management ortouch screen configuration.

At this point, those who have used Siemens PLC programming software will surely find similarities with Siemens PLC programming. Proper use of structures can reduce memory waste.

Leave a Comment