Global/Local Variables
Video Tutorial
XG5000 allows the user to define Global and Local variables.
-
Global variables can be accessed from any Scan Program and Task.
-
Local variables can only be accessed from the Scan Program and Task it is defined in.
-
Variables must be declared before using them in Scan programs and Tasks.
Variable Type | Description |
---|---|
VAR_GLOBAL | Global variable type available to read/write. |
VAR_GLOBAL_CONSTANT | Global constant type that is read only. |
VAR | Local variable type available to read/write. |
VAR_CONSTANT | Local constant variable that is read only. |
VAR_EXTERNAL | Declaration to use a Global Variable in local program. |
VAR_EXTERNAL_CONSTANT | Declaration to use Global Constant in local program. |
Step | Action |
---|---|
1 |
In an open XG5000 Project, open the Global/Direct Variables file in the Project window.
|
2 |
Choose the Variable Kind for the Global variable.
|
3 |
Enter a variable name in the Variable column. This example has the variable name GlobalTest1.
|
4 |
Choose a Type for the Global variable.
|
5 |
An Address can be entered if this Global Variable accesses a Direct Variable address. This example shows the variable accessing Direct Variable Address %MX0.
|
6 |
An Initial Value can be given to the variable. This is the value of the variable on first scan of the CPU. This example shows an initial value of FALSE.
|
7 |
Select if the variable value is retained on power cycle of the CPU. Check the Retain box to store value on power cycle.
|
8 |
Check EIP/OPC UA if the variable is going to be used in EtherNet/IP P2P communication.
|
9 |
Add a comment to describe the variable.
|
Step | Action |
---|---|
1 |
In an open XG5000 Project, open the Local Variables file in the desired Scan Program or Task. This example shows a Scan Program called NewProgram.
|
2 |
Choose the Variable Kind for the local variable.
|
3 |
Enter a variable name in the Variable column. This example has the variable name LocalTest1.
|
4 |
Choose a Type for the local variable.
|
5 |
An Address can be entered if this local variable accesses a Direct Variable address. This example shows the variable accessing Direct Variable Address %MX1.
|
6 |
An Initial Value can be given to the variable. This is the value of the variable on first scan of the CPU. This example shows an initial value of FALSE.
|
7 |
Select if the variable value is retained on power cycle of the CPU. Check the Retain box to store value on power cycle.
|
8 |
Check EIP/OPC UA if the variable is going to be used in EtherNet/IP P2P communication.
|
9 |
Add a comment to describe the variable.
|
To use a Global variable in a Scan program or Task, it must be declared as a VAR_EXTERNAL variable type for that Scan program.
-
This variable type can be found in the drop down when creating a variable.
-
VAR_EXTERNAL_CONSTANT is used the same way for a Global constant variable.
This Example shows declaring the VAR_EXTERNAL to allow the NewProgram Scan Program to use the GlobalTest1 global variable in code.
LP003-1