This tutorial will show how to create and use a data structure in MasterTool X
Components
Equipment: 1 computer/laptop.
1 XF300/315/325/325-W
Software: MasterTool X
Tutorial Sections
- ARCHITECTURE
- DEVELOPMENT
1.ARCHITECTURE
A computer/laptop is required to use MasterTool X.
Figure 1. Computer running MasterTool X
2.DEVELOPMENT
The use of data structures (STRUCT) is very common in automation when you want to organize variables related to the same equipment or process, facilitating reading, reuse, and maintenance of the code.
Creating a STRUCT (DUT)
To create a structure in MasterTool IEC XE:
- Right-click on Application
- Select Add Object
- Choose the option DUT (Data Unit Type)
- Define a name for the structure
Example:
motor
Figure 2. Creating a Struct – Data Structure
Declaring the structure
Within the DUT, declare the variables that are part of the structure:
TYPE motor :
STRUCT
start: BOOL;
status : BOOL;
current : INT;
temperature : REAL;
END_STRUCT
END_TYPE
Concept
The STRUCT allows grouping several variables within a single type, representing a logical object, such as a motor.
In this case, all the motor's information is organized in a single block:
- Start command
- Status
- Current
Temperature
Figure 3. Declaration of the structure's internal variables
Instantiating the structure
After creating the STRUCT, it needs to be instantiated in the program.
In user.prg, declare:
motor1 : motor;
motor2 : motor;
Using it in logic
To access the elements of the structure, use the following syntax:
instance_name.variable_name
Examples:
motor1.startmotor1.statusmotor2.current
Practical example
In Ladder logic:
- A normally open contact:
motor1.start - Activating a coil:
motor1.status
The same can be done for another motor:
motor2.start→motor2.status
Figure 4. Using the Struct in logic
How it works
Each instance of the structure works independently:
motor1has its own valuesmotor2has its own values
Even though they are of the same type (motor), they do not interfere with each other.
Applications in automation
The use of STRUCT is ideal for:
- Representing equipment (motors, valves, sensors)
- Organizing related variables
- Creating cleaner and standardized code
- Facilitating system maintenance and expansion
- Reusing structures in different parts of the project
Important notes
- The STRUCT is created as a DUT
- It needs to be instantiated for use
- Each instance is independent
Significantly improves project organization
Figure 5. Structure operation in logic
Comments
0 comments
Please sign in to leave a comment.