Skip to main content

Operator: __VARINFO

The operator is an extension of the IEC 61131-3 standard.

The operator yields information about a variable. You can save the information as data structure in a variable of data type __SYSTEM.VAR_INFO.

Syntax in the declaration

<name of the info variable> : __SYSTEM.VAR_INFO; // Data structure for info variable

Syntax for calls

<name of the info variable> := __VARINFO( <variable name> ); // Call of the operator
Example 153. Example
FUNCTION_BLOCK FB_Velocity
VAR_INPUT
        rVelocity: REAL := 1.2;
END_VAR
VAR_OUTPUT
END_VAR
VAR
        infoVelocity: __SYSTEM.VAR_INFO; //Info of Velocity
END_VAR

infoVelocity := __VARINFO(rVelocity); // Gets the info of Velocity locally
PROGRAM PLC_PRG
VAR
        iCounter : INT := 0; // Counts the calls
        infoCounter : __SYSTEM.VAR_INFO; //Info of Counter
        arrA : ARRAY [1..2, 1..2, 1..2] OF INT := [0, 1, 2, 3, 4, 5, 6, 7]; // Stores the A data
        infoA : __SYSTEM.VAR_INFO; //Info of A
        fbVel : FB_Velocity;
END_VAR

iCounter := iCounter + 1;
infoCounter := __VARINFO(iCounter);
infoA := __VARINFO(arrA);
fbVel();

The iCounter and arrA variables are recognized in the application code. The variable information is saved in the infoCounter and infoA variables. Moreover, the FB_Velocity function block is instantiated.



Data Type: __SYSTEM.VAR_INFO

Name

Data Type

Initialization

Description

ByteAddress

DWORD

0

Address of the variable

Example: 16#072E35EC

Note: For bit access of a variable <variable name>.<bit index>, the address of the variable which contains the bit is given.

ByteOffset

DWORD

0

Offset of the variable address (in bytes)

Example: 13936 bytes

Note: If the variable is global, then the offset is relative to the beginning of the area. If the variable is a local variable in a function or method, then the offset is relative to the current stack frame. If the variable is a local variable in a function block, then the offset is relative to the function block instance.

Area

DINT

0

Memory area number Area in the runtime system

Example: -1

Means that the variable is not global in the memory, but relative to an instance or on the stack

Note: The memory areas are device-dependent.

BitNr

INT

0

Number of bits (in bytes)

Example: 16#00FF bytes

Note: If the variable is not an integer data type, then: BitNr = -1 = 16#FFFF

BitSize

INT

0

Memory size of the variable (in bits)

Example: 16 bits

BitAddress

UDINT

0

Bit address of the variable

Requirement: The variable is located in the input memory area I, output memory area Q, or marker memory area M. Otherwise the value is undefined.

TypeClass

TYPE_CLASS

TYPE_BOOL

Data type class of the variable

Example: TYPE_INT, TYPE_ARRAY

Note: For user-defined data types or function block instances, TYPE_USERDEF is output as the data type class.

TypeName

STRING(79)

‚‘

Date type name of the variable as STRING(79)

Note: For user-defined data types, the function block name or the DUT name is output.

Example: 'INT', 'ARRAY'

NumElements

UDINT

0

Number of array elements

Requirement: The variable has the data type ARRAY.

Example: 8

BaseTypeClass

TYPE_CLASS

TYPE_BOOL

Elementary basic data type of the array elements

Requirement: The variable has the data type ARRAY.

Example: TYPE_INT for arrA : ARRAY [1..2,1..2,1..2] OF INT;

ElemBitSize

UDINT

0

Memory size of the array element (in bits)

Requirement: The variable has the data type ARRAY.

Example: 16 bits for arrA : ARRAY [1..2,1..2,1..2] OF INT;

MemoryArea

MEMORY_AREA

MEM_MEMORY

Information about the memory area

  • MEM_GLOBAL: Global memory area

    Example: in Area 0

  • MEM_LOCAL: Local memory area

    in Area -1

  • MEM_MEMORY: Marker memory area %M

    Example: in 16#10 in Area 1

  • MEM_INPUT: Input memory area %I

    Example: in 16#04 in Area 2

  • MEM_OUTPUT: Output memory area %Q

    Example: in 16#08 in Area 3

  • MEM_RETAIN: Retain memory area

    Example: in 16#20 in Area 0

Example: MEM_GLOBAL

Note: The memory area configuration is device-dependent.

Symbol

STRING(39)

‚‘

Variable name as STRING(39)

Example: 'iCounter', 'arrA'

Comment

STRING(79)

‚‘

Comment of the variable declaration

Example: 'Counts the calls' or 'Stores the A data'