External variables / V.E variables

Data can be exchanged between the NC program and the PLC via the HLI using external variables. Each channel has a separate data area for external variables known only in the channel. In addition, there is a cross-channel global data area which all channels can access.

At the PLC end, the data areas for the external variables are represented as an ARRAY OF UDINT. The index of the individual array elements starts with the value 0.

Each external variable always occupies one memory block of HLI_EXT_VAR_STR_MAXIDX + 1 (24) bytes, irrespective of its data type. If an array of external variables was defined, the individual variables are saved packed in the memory area (several variables per memory block). Here, several consecutive memory blocks may be used depending on the array size.

When the PLC accesses external variables, the index of the variables in the memory area of the external variables must first be determined:

Example for calculating an index:

4. Variable (VarNr = 4):

Offset = (VarNr –1)* (HLI_EXT_VAR_STR_MAXIDX + 1) / 4 + 1

A variable with the index = 3 results in an offset in the memory of 13.

The memory area must then be accessed depending on the actual data type of the external variables. All information required for this is contained in the configuration list of the external variables.

Please refer to the documentation [EXTV] for further details on external variables.

In the TwinCAT runtime environment, the number of external variables can be configured in the System Manager.

An example program to access external variables is available under the name or HLI-Ve1.pro.

External variable

Description

Memory area for data exchange between NC program and PLC

Data type

CNC global

POINTER TO HLI_GLOB_V_E_DATA:

 

channel-specific:

ARRAY[0..HLI_SYS_CH_MAXIDX] OF POINTER TO HLI_CHAN_V_E_DATA

ST path

CNC global:

gpVEGlobal

 

channel-specific:

gpVECh[channel_idx]

Access

pLRealVal     : POINTER TO LREAL;

LRealVal       : LREAL;

VeOffset        : DINT;

 

VeOffset := (VarNr –1) * (HLI_EXT_VAR_STR_MAXIDX + 1) / 4 + 1;

pLRealVal := gpVEGlobal^.ext_var32[VeOffset]);

LRealVal := pLRealVal^;

Special features

Access depends on the data type of the external variables.