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.

Syntax
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 declaration of such a section is allowed before the end of a configuration (END_CONFIGURATION) as well as before the end of a resource (END_RESOURCE).

The following elements are possible with the appropriate hierarchy for name_1, name_2 etc. (= icon images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/check.svg ) or not (= icon images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/error.svg ):



Within the VAR_CONFIG section for a

No.

Element

Configuration

Resource

1

name of a resource

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/check.svg

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/error.svg

2

name of a program instance

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/check.svg

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/check.svg

3

name of a variable

These variable sections are supported: →internal variables (VAR...END_VAR), →input variables, →output variables, →external variables , →global variables

These variable sections are not supported: →in-/output variables, →temporary variables
If you are using such variables, they are not highlighted as faulty within the code Subsequently, it is not possible to build the application or load it onto the PLC.

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/check.svg

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/check.svg

4

name of a structure element,
if the data type of the global variables is a →structured data type

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/information.svg It is possible that a structure element is defined with a partial address.

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/check.svg

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/check.svg

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). images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/warning.svg 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:

Example

Explanation

%QB7

output, byte, 7th element (in the 1st level)

%IX1

input, bool, 1st element (in the 1st level)

%I1

input, bool, 1st element (in the 1st level)

%IW2.5.7.3

input, word, 3rd element in the 7th "module" in the 5th "rack" of the 2nd "bus"

Necessary structure for physical address

Enter a physical address according to this structure:


Character

Meaning

1.

%

initiates the address

2.

prefix for location

defines the location


I

input


Q

output


M

memory

3.

prefix for size

defines the size


X or none

bool (single bit)


B

byte (8 bits)


W

word (16 bits)


D

double word (32 bits)


L

long word (64 bits)

4.

one or more →unsigned integers
You must separate the integers by . in order to enter hierarchical levels.
Enter the highest level as leftmost number, the lower levels as numbers to the right.

Restriction

logi.CAD 3 supports max. 5 levels. The highest possible number per level is: 4_294_967_295 (that corresponds to UINT32_MAX)
The underscore characters _ are inserted as separator to make the value more readable, hence _ is not significant.

defines the address

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

  • On using the VAR_CONFIG sections: Currently, logi.CAD 3 supports VAR_CONFIG sections only when using the →EtherCAT IO provider. For all other cases, it is possible to use the syntax but the corresponding code is not created yet and loaded onto the →PLC (so the VAR_CONFIG sections have no impact on the execution of the application).

  • The VAR_CONFIG section does not provide an instance specific initialization.

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/information.svg 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) .

Example 1: Section within resource
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

Example 2: Section within 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

Example 3: Section within configuration using prefixes
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
Addendum for examples 1 to 3: Possible ST-code
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