The objective of this tutorial is to explain how to avoid the main syntax errors when creating a variable type in a MasterTool X project.
Components
Equipment: 1 computer/notebook.
Software: MasterTool X
Tutorial Sections
- ARCHITECTURE
- DEVELOPMENT
1. ARCHITECTURE
A computer/notebook will be required to use MasterTool X.
Figure 1. Computer running MasterTool X
2. DEVELOPMENT
When creating variables in MasterTool IEC XE, it is essential to respect the syntax rules defined by the IEC 61131-3 standard. Failure to comply with these rules results in compilation errors, preventing the program from being downloaded to the PLC.
This tutorial addresses the most common errors and the correct way to add comments to variables.
Good practices for creating variables
- Always start the name with a letter
- Use clear and descriptive names
- Use underscores to separate words
- Avoid generic names like var1, x, test
Common errors in variable naming
1. Variable starting with a number It is not allowed to start a variable name with numbers.
Wrong:
1sensor : BOOL;Correct:
sensor1 : BOOL;Figure 2. Creating a variable with a number in the name
2. Using spaces in the variable name Spaces are not allowed in variable names.
Wrong:
sensor nivel : BOOL;Correct:
sensor_nivel : BOOL;Figure 3. Creating a variable with a space in the name
3. Using special characters Do not use special characters such as: @ # $ % & * - + . , / \
Wrong:
nivel%alto : BOOL;Correct:
nivel_alto : BOOL;The only allowed characters are:
• Letters (A–Z, a–z)
• Numbers (0–9)
• Underscore (_)
Figure 4. Creating a variable with a special character in the name
How to add a comment when creating a variable
It is possible to add comments directly to the variable declaration, making it easier to read and maintain the code.
Commenting a local variable
Simply use `//` after the declaration:
nivel_tanque : INT; // Current tank level in %The comment does not interfere with the program's execution and serves only as documentation.
Advantages of commenting variables
- Facilitates understanding of the logic
- Reduces maintenance errors
- Helps other programmers
- Improves project organization
Well-written comments are as important as the logic itself.
Figure 5. Creating a comment for a variable
Comments
0 comments
Please sign in to leave a comment.