Structured Text Programming
To create a new Structured Text program as a scan program, right-click on Scan Program in the Project window and select Add Item è Program…
After creating a new Structured Text program, you see the new program consists of 2 items Local Variables and Program attached to in the Project window.
Local Variables
You can manage the local variables used in this Structured Text program in this window.
Program
You can edit the Structured Text program in this window.
The XG5000 program doesn’t support the declaration of variables in the Structured Text program. Instead, XG5000 uses windows to create new variables.
Step | Action |
---|---|
1 |
In the Program window, select Variable Add/Select from the right-click menu as shown below, or press the CTRL key and the 1 key (above the Q key, not on the number pad) at the same time.
|
2 |
The Select Variable window opens. Take the following steps.
|
3 |
The Variable Add window opens.
|
4 | Click the OK buttons to close Variable Add window and Select Variable window. |
This section shows how to use a pre-created variable (local or global), direct variable or flag.
Step | Action |
---|---|
1 |
In the Program window, select Variable Add/Select from the right-click menu as shown below or press the CTRL key and the 1 key (above the Q key, not on the number pad) at the same time.
|
2 |
The Select Variable window opens.
|
Note: If you select the Direct Variable in the Variable List category, you may not see any direct variables. This is because only direct variables with comments are displayed.
Here is how to add a comment to a direct variable.
Step | Action |
---|---|
1 |
Double-click Global/Direct Variables in the Project window.
|
2 |
The Global/Direct Variables window opens.
|
3 |
This direct variable is displayed in the Select Variable window.
|
There are 2 methods to enter a function in the Structured Text program.
-
Method 1: Use the Function/Function Block window. Use this method if you don’t know the function name yet.
-
Method 2: Type in the function name directly. This method is quicker if you already know the function name.
Step | Action |
---|---|
1 |
In the Program window, select F/FB Select from the right-click menu as shown below or press the F10 key.
|
2 |
The Function/Function Block window opens.
|
3 |
The function is displayed in the program.
|
If you know the name of the function you want, you can type it directly into the program window.
In the following example, the INT_TO_DINT function is entered.
After you type in the first character 'I', the following list pops up.
This list includes the functions, function blocks, variables and key words that their name starts with the character ‘I’. This list becomes shorter if you enter more characters. You can type in the entire function name or select the function from the list as shown below.
The INT_TO_DINT function is entered.
You may have noticed there was a little difference in the display after the function was entered by Method 1 or Method 2.
Entered by Method 1:
Entered by Method 2:
If you move the mouse cursor over the function, XG5000 displays the default format of the function as reference as shown below.
When you use a function, you must use the same data type suggested for each input and output.
The output of a function can be assigned to a variable or used in a formula.
Example 1: The output is assigned to a variable.
Example 2: The output is used in a formula.
The ‘IN:=‘ for inputs can be eliminated. The following are valid expressions.
There are 2 methods to enter a function block in the Structured Text program.
-
Method 1: Use the Function/Function Block window. Use this method if you don’t know the function block name yet.
-
Method 2: Type in the function block name directly. This method is quicker if you already know the function block name.
Step | Action |
---|---|
1 |
In the Program window, select F/FB Select from the right-click menu as shown below or press the F10 key.
|
2 |
The Function/Function Block window opens.
|
3 |
The Select Variable window opens.
|
4 |
The Variable Add window opens.
|
5 |
The instance of the function block is displayed in the program.
|
If you know the name of the function block you want, you can type it directly into the program window.
In the following example, the TMR function block is entered.
Step | Action |
---|---|
1 |
After you type in the first character ‘T’, the following list pops up:
This list includes the functions, function blocks, variables and key words that their name starts with the character ‘T’. This list becomes shorter if you enter more characters. You can type in the entire function block name or select the function block from the list as shown below.
|
2 |
After you enter the function block name, the Select Variable window opens.
|
3 |
The Variable Add window opens.
|
4 |
The instance of the function block is displayed in the program.
|
XG5000 displays the data type defined for each input(s) indicated with ‘:=‘ and output(s) indicated with ‘=>’.
A variable or constant can be assigned to each input. Only a variable can be assigned to each output.
All input(s) must be used in the program, but any output can be omitted. The following expressions are all valid.
The instance of the function block is a variable. The input(s) and output(s) associated with the function block become member variables for the instance.
For example, when the instance of the TMR function block is entered in the program, the following 5 member variables are created automatically.
Each member variable can be accessed with the name in the following format.
<Variable name of the instance>.<Member variable name>
The example programs in the left can be written as follows.
The member variables can be used in the program like this.
Entering a statement like the IF statement is very easy with the XG5000 software.
Type in IF and press the Enter key.
XG5000 displays this template of the IF statement.
You just need to program the (*condition*) and (*statements*) parts like this.
Note: The ELSIF statement needs to be added manually.
Template:
Sample Program:
Template:
Sample Program:
With Exit:
Template:
Sample Program:
With Exit:
Template:
Sample Program:
With Exit:
Template:
Sample Program:
There are two styles you can use to add a comment in the Structured Text program-‘Line comment’ and ‘Block comment’.
-
Line Comment: Use ‘//’ (Two slashes) for a single line comment.
-
Block Comment: Use ‘(*’ and ‘*)’ for a single line or multiple line comment.
Format:
// comment
Example:
Tip: After typing in a text, select it and execute the Line Comment Set/Reset command from the right-click menu to convert the text to the line comment.
Format:
(* comment *)
(* comment
comment
comment *)
Example:
Tip: After typing in a text, select it and execute the ‘Block Comment Set’ command from the right click menu to convert the text to the block comment.
When you try to download your user project into the XMC, XG5000 checks your programs. If there are any errors, XG5000 doesn’t download the user project. You need to correct all errors to download the user project. You may check your program occasionally while you are still writing a program.
How to check your program
Step | Action |
---|---|
1 |
Select Check Program… from the pull-down menu View or click the following icon.
|
2 |
The Program Check window opens. You can configure the program check rules, but the default setup should be okay. Click the OK button to start the program check.
|
3 |
The program check results are displayed in the Check Program window. (As default, this window is displayed in the right bottom of the XG5000 window.)
|
LM113-4