2 pointers, Pointers, Drive plc developer studio – Lenze DDS v2.3 User Manual

Page 260

Advertising
background image

Drive PLC Developer Studio

IEC 61131-3 Data types

10-4

l

DDS EN 2.3

If an integral project component, the function CheckBounds is called up automatically. A separate
call for the function in the implementation is not required.

If the function CheckBounds is not an integral project component, an array is not prevented from
exceeding its limits.

Where indirect accesses made to an array outside its limits, CheckBounds forces access to the first
or last array element.

Implementation

Declaration part

FUNCTION Checkbounds : INT
VAR_INPUT

index,lower,upper:INT;

END_VAR

Instruction part

IF index < lower THEN

CheckBounds := lower;

ELSEIF index > upper THEN

CheckbBounds := upper;

ELSE

CheckBounds := index;

END_IF

The following program example for testing the CheckBounds function accesses outside the limits
of a defined array. The function CheckBounds ensures that the value TRUE is not assigned to A[10],
but to the still-valid upper range limit A[7]. The CheckBounds function can thus be used to intercept
any access beyond the array limits.

Declaration part

PROGRAM PLC_PRG
VAR

A:ARRAY[0..7] OF BOOL;
B:INT:=10;

Instruction part

A[B]:=TRUE;

10.2.2

Pointers

Pointers are used to save addresses of variables or function blocks at program runtime.

Warning!

Applied wrongly, pointers may crash the target system. For this reason, do not use pointers.

If you use pointers, do so with great care. Writing of WORD data types on odd addresses or
accessing system memory areas can cause errors.

Show/Hide Bookmarks

Advertising