Which products are affected?
ESP-DDS2-P (Global Drive PLC Developer Studio Version 2.0, 2.1)
What happens?
The data memory address of an ARRAY type variable is assigned to a variable of the type POINTER TO ARRAY. If, with the aid of this POINTER variable, the value of an element of this array is now read out, incorrect values are calculated, e.g. -32760.
Example:
Declaration
anVar:ARRAY[0..10] OF INT;
pnVar:POINTER TO ARRAY[0..10] OF INT;
nVar:INT;
Implementation:
anVar[1]:=1234; (*Wert dem zweiten Element des Arrays zuweisen*)
pnVar:=ADR(anVar); (*Datenspeicheradresse des Arrays ermitteln*)
nVar:=pnVar^[1]; (*nVar = -32760*)
When does the problem occur?
The above-described behaviour occurs with pointer accesses to array elements with a constant index.
In the example above, on the line nVar:=pnVar^[1]; there is access to the array element with the constant index 1.
Possible diagnostics?
None.
Short-term measures/recommendations?
Avoid using pointers in PLC programs.
If pointers are absolutely necessary, address an array element of the pointer variables only indirectly.
Example:
Implementation:
anVar[1]:=1234; (*Wert dem zweiten Element des Arrays zuweisen*)
pnVar:=ADR(anVar); (*Datenspeicheradresse des Arrays ermitteln*)
nIndex:=1; (*Indirekte Adresse des Array-Elements*)
nVar:=pnVar^[nIndex]; (*nVar = 1234*)
This function restriction has been remedied in DDS Version 2.2.
Evaluation:
Lenze recommends avoiding using pointers in PLC programs as far as possible. For this reason pointer variables tend to be used rarely. If pointer variables are used in the above-described manner, this function restriction will be recognised upon commissioning of the machine/system at the latest.