发表于:2004/11/3 19:59:00
#20楼
Global and local variables
The scope of each variable which is determined by the use of the variable keyword is limited either to a POU or to the whole project. Therefore two types can be distinguished:
Local variables
Global variables
If a variable can be used only within a POU it is called local variable. In those cases the variable keywords VAR, VAR_INPUT and VAR_OUTPUT can be used.
If a variable can be used within the whole project it is called global variable. It has to be declared as VAR_GLOBAL in the global declaration and as VAR_EXTERNAL in each POU where it is used.
It might be useful to declare all I/Os as global variables. In the global variable declaration they should be declared as located variables and in the VAR_EXTERNAL declaration of the POU they should be declared as symbolic variables. The typing effort in case of address changes is less doing it this way.
The scope of each variable which is determined by the use of the variable keyword is limited either to a POU or to the whole project. Therefore two types can be distinguished:
Local variables
Global variables
If a variable can be used only within a POU it is called local variable. In those cases the variable keywords VAR, VAR_INPUT and VAR_OUTPUT can be used.
If a variable can be used within the whole project it is called global variable. It has to be declared as VAR_GLOBAL in the global declaration and as VAR_EXTERNAL in each POU where it is used.
It might be useful to declare all I/Os as global variables. In the global variable declaration they should be declared as located variables and in the VAR_EXTERNAL declaration of the POU they should be declared as symbolic variables. The typing effort in case of address changes is less doing it this way.