2.14.6
Determining offset addresses for data block structures
General
Another task, which occurs frequently, is symbolic determination of an offset address within
a structured DB, e.g., an ARRAY or STRUCTURE is stored somewhere within the DB. After
loading the address register symbolically with the start address, you might like to access the
individual elements of the ARRAY or STRUCTURE via an address register. One way of
loading the address register symbolically is to use an FC whose input parameter is a pointer.
The address of the ARRAY or STRUCTURE is then assigned symbolically to the input
parameter of this FC in the program. The program code in the FC now determines the offset
address from the input parameter, and passes the offset address in the address register
(AR1) to the calling function. Symbolic addressing is thus possible even with indirect access.
FUNCTION FC 99: VOID
VAR_INPUT
Addr: POINTER;
END_VAR
BEGIN
NETWORK
TITLE =
P##Addr;
L
LAR1 ;
D [AR1,P#2.0];
L
LAR1 ;
END_FUNCTION
Basic logic functions: PLC Basic program powerline (P3 pl)
Function Manual, 11/2006, 6FC5397-0BP10-2BA0
Comment
//Points to variable
//Retrieve pointer from Addr
//Offset part of pointer of variable
Detailed description
2.14 Programming tips with STEP 7
281