Variables Configuration - VAR_CONFIG

Use the variables configuration for mapping variables of functions blocks to the process map. For declarations in the function block, assign the variables to the device inputs/outputs without providing the full address. Later, the exact address is provided centrally for all function block instances of the application in a global variable list including VAR_CONFIG declarations. This global variables list with the VAR_CONFIG declarations is termed the “variables configuration”.

Hint

For changes to variables that are assigned to I/O addresses, CODESYS displays them immediately In the process map. For changes to variables that are mapped by a variables configuration, CODESYS displays them not until the end of the responsible task.

Declaration of variables in functions blocks

When declaring variables in a function block, declare the variables between the keywords VAR and END_VAR and assign incomplete addresses to the variables. Mark these incomplete addresses with an asterisk (*).

Syntax:

<identifier> AT %<I\|Q>*:<data type>;

Example

Define two local I/O variables: the input variable xLocIn and the output variable xLocOut.

FUNCTION_BLOCK locio
VAR
  xLocIn AT %I*: BOOL := TRUE;
  xLocOut AT %Q*: BOOL;
END_VAR

Final definition of addresses in the variables configuration of the global variables list

In the global variables list that you use as the variables configuration, define the variable declarations with the absolute addresses between the keywords VAR_CONFIG and END_VAR.

You must declare the VAR_CONFIG variables with the complete instance path, separating the individual POU and instance name by a dot (.). The declaration must include an address whose class (input/output) agrees with the class of the incomplete address (%I*, %Q*) in the function block. The data type must also agree.

Syntax:

<instance variable path> AT %<I\|Q><location>: <data type>;

If the path instance does not exist, then an error is reported. CODESYS prints an error also if there is not an address configuration available for a variable that you declared with an incomplete address.

Example

The locio function block in the example above is used in a program as follows:

PROGRAM PLC_PRG
VAR
  locioVar1: locio;
  locioVar2: locio;
END_VAR

A correct variables configuration in a global variable list could then look like this:

VAR_CONFIG
  PLC_PRG.locioVar1.xLocIn AT %IX1.0 : BOOL;
  PLC_PRG.locioVar1.xLocOut AT %QX0.0 : BOOL;
  PLC_PRG.locioVar2.xLocIn AT %IX1.0 : BOOL;
  PLC_PRG.locioVar2.xLocOut AT %QX0.3 : BOOL;
END_VAR

See also

Creating a variables configuration

Requirement: You have a project open that includes a controller configuration with a field device. The project contains a program (e.g. PLC_PRG) and a function block (e.g. func1). The field device has inputs and outputs. The textual view is selected in the options for the declaration editor.

In the function block, assign variables to device I/Os with incomplete addresses and then create a variables configuration.
  1. Double-click a function block in the device tree (e.g. func1).

    ⇒ The function block editor opens.

  2. Type the following between the keywords VAR and END_VAR: xLocIn AT %I*: BOOL := TRUE; and XLocOut AT %Q*:BOOL; in the next line.

    ⇒ You have declared an input variable xLocIn and assigned it to the incomplete input address %I* of a field device. You have assigned the declared output variables have to the incomplete output address %Q*.

  3. Click the PLC_PRG object in the device tree and add the following to the declaration section of the program between VAR and END_VAR:

    locioVar1: func;

    locioVar2: func;

  4. Right-click the Application object in the device tree and click Add Object ‣ Global Variable List and then click Add in the Add Global Variable List dialog box.

    ⇒ The global variables list is added to the device tree and opens in the editor.

  5. Change the keyword VAR_GLOBAL to VAR_CONFIG.

  6. Click Declarations ‣ Add all instance paths .

    ⇒ The following instance paths are added:

    PLC_PRG.logioVar1.xLocIn AT %I*;

    PLC_PRG.logioVar2.xLocIn AT %I*;

    PLC_PRG.logioVar1.xLocOut AT %Q*;

    PLC_PRG.logioVar2.xLocOut AT %Q*;

  7. Now, replace the incomplete addresses %I* and %Q* with the absolute, complete addresses.

See also