Declaring VAR_CONFIG sections within PLC-object
You require a VAR_CONFIG section to assign instance specific locations to symbolically represented variables. This section is possible within a →configuration as well as within a →resource.
This article describes the declaration of the VAR_CONFIG section within the PLC-object.
VAR_CONFIG
name_1 AT %address (* optional_begin *) {SIZE := value} (* optional_end *);
name_2 AT %address (* optional_begin *) {SIZE := value} (* optional_end *);
name_3 AT %address (* optional_begin *) {SIZE := value} (* optional_end *);
...
END_VAR
Meaning |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
one or several instance specific location assignment for symbolically represented variables The following elements are possible with the appropriate hierarchy for name_1, name_2 etc. (= icon
) or not (= icon
):
The elements must be separated from each other by specifying this character: .If a defined element within the VAR_CONFIG section is ambiguous (because e.g. a global variable and the program instance have the same name, now it is possible to define the prefix VAR_GLOBAL# or PROGRAM# in order to determine which element should be used (see example using prefixes below). In spite of this possibility, logi.cals recommends to use a unique →IEC-identifier as name when declaring the appropriate element (e.g. a global variable). Use the optional keyword AT to assign a physical address in the →PLC to the symbolic variable. Examples for physical addresses:
Enter a physical address according to this structure:
The attribute SIZE is only required for specifying the bit size in case of not elementary data types. In case of elementary data types, this attribute is optional. You might want to use it in order to e.g. copy just one byte from the IO-segment into a WORD variable. If SIZE is not specified, the bit size of the appropriate data type is used (if an elementary data type is the basis). Enhancements to IEC-standard The VAR_CONFIG section within a resource and the attribute SIZE are enhancements to the →IEC-standard. Moreover, it is possible to declare a VAR_CONFIG section within a VarCfg-object and to insert here just a reference. Restrictions
|
The declarations of the corresponding variables and/or data types must be provided so that the following examples are free of errors as far as possible (see "Addendum for examples 1 to 3" for a possible ST-code) .
CONFIGURATION LocalConfiguration
RESOURCE local ON BuiltInPlc { ON_CHANNEL := LocalChannel }
VAR_GLOBAL
valvePos : INT;
END_VAR
TASK DefaultTask(INTERVAL := TIME#500ms, PRIORITY := 38229);
PROGRAM iCounter WITH DefaultTask :
Counter;
VAR_CONFIG
(* instance specific location assignments for the variables *)
iCounter.globVar1.Elem1 AT %IW1.2.3; (* assigning the location '%IW1.2.3', without size specification *)
iCounter.globVar2 AT %IB1.4.6 {SIZE:=2}; (* assigning the location '%IB1.4.6', with size specification *)
(* instance specific location assignments for resource-global variables *)
valvePos AT %QW28;
END_VAR
END_RESOURCE
END_CONFIGURATION
CONFIGURATION LocalConfiguration
RESOURCE local ON BuiltInPlc { ON_CHANNEL := LocalChannel }
VAR_GLOBAL
valvePos : INT;
END_VAR
TASK DefaultTask(INTERVAL := TIME#500ms, PRIORITY := 38229);
PROGRAM iCounter WITH DefaultTask :
Counter;
END_RESOURCE
VAR_CONFIG
(* instance specific location assignments for the variables *)
local.iCounter.globVar1.Elem1 AT %IW1.2.3; (* assigning the location '%IW1.2.3', without size specification *)
local.iCounter.globVar2 AT %IB1.4.6 {SIZE:=2}; (* assigning the location '%IB1.4.6', with size specification *)
(* instance specific location assignments for resource-global variables *)
local.valvePos AT %QW28;
END_VAR
END_CONFIGURATION
CONFIGURATION LocalConfiguration
RESOURCE local ON BuiltInPlc { ON_CHANNEL := LocalChannel }
VAR_GLOBAL
valvePos : DT1;
END_VAR
TASK DefaultTask ( INTERVAL := TIME#500ms , PRIORITY := 38229 );
PROGRAM valvePos WITH DefaultTask :
Counter;
VAR_CONFIG
(* ERROR: The following symbolically represented variable is ambiguous because a global variable is named 'valvePos' and the program instance is, too. *)
(* Best practice is to rename the global variable and the program instance so that they are declared with unique IEC-identifiers as name. *)
valvePos.Elem1 AT %I1.2.3;
(* Otherwise enter the prefix 'VAR_GLOBAL#', if the global variable 'valvePos' should be used. *)
VAR_GLOBAL#valvePos.Elem1 AT %I1.2.3;
(* Or enter the prefix 'PROGRAM#', if the program instance 'valvePos' should be used. *)
PROGRAM#valvePos.globVar1.Elem1 AT %I1.2.3;
END_VAR
END_RESOURCE
END_CONFIGURATION
PROGRAM Counter
VAR_GLOBAL (* declaration of the corresponding variables; here: of global variables *)
globVar1 : DT1;
globVar2 : INT;
END_VAR
END_PROGRAM
TYPE
DT1 : STRUCT (* declaration of the corresponding data type *)
Elem1 AT %I* : INT;
END_STRUCT;
END_TYPE