GetPointer32

Provides pointer information

The GetPointer32 function provides variables' 32-bit pointer information in a predefined data unit type (DUT) of the data type POINTER32 which can be used by functions or function blocks. With such pointer information and the corresponding pointer functions, functions or function blocks can directly read from or write to the external data's address area.

Parameters

Input

Unnamed input (ANY)

Input variable of any data type that must be located in the DT, FL or Y memory area.

Output

Unnamed output (POINTER32)

The pointer information of the input variable.

Remarks

User-defined functions or user-defined function blocks can use the pointer information as follows:

  • The pointer element iSize can specify the number of values, i.e. (number of elements = Pointer.iSize / Size_Of_Var (DataElement))

  • With corresponding pointer functions AreaOffs32_ToVar and Var_ToAreaOffs32 and with the pointer elements iArea and diOffset, you can directly read from or write to the external data's address area.

  • With the memory area instructions Is_AreaDT or Is_AreaFL and with the address instructions AdrDT_Of_Offs32 or AdrFL_Of_Offs32, you can also use FP instructions with the external data's address areas.

The input variable must be located in the memory area DT or FL for the following reasons:

  • because the memory area instructions Is_AreaDT or Is_AreaFL and the address instructions AdrDT_Of_Offs32 or AdrFL_Of_Offs32 work only with these memory areas.

  • because the pointer instructions AreaOffs32_ToVar and Var_ToAreaOffs32 work correct only within these memory areas.

This instruction replaces the instruction AreaOffs_OfVar.

Example

POU header

All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.

	VAR
		arData: ARRAY [0..2] OF REAL:=[10.0,20.0,30.0];
		diNumberOfElements: DINT:=0;
		rSum: REAL:=0.0;
		rMean: REAL:=0.0;
		rDeviation: REAL:=0.0;
	END_VAR

LD body

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 6 ;
        NETWORK_BODY
B(B_COMMENT,,These functions show the write access to an input array by using the GetPointer32 function.ø^The input array arDara is initialized with [10.0~ 20.0~ 30.0],3,0,42,2,);
B(B_VARIN,,arData,6,4,8,6,);
B(B_F,FunCalcStatisticsInitArray1!,,15,3,28,6,,?DprArray);
B(B_F,GetPointer32!,,8,4,15,6,,?D?C);
L(1,0,1,6);
        END_NETWORK_BODY
    END_NET_WORK
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 9 ;
        NETWORK_BODY
B(B_VARIN,,arData,6,4,8,6,);
B(B_F,GetPointer32!,,8,4,15,6,,?D?C);
B(B_VAROUT,,diNumberOfElements,29,4,31,6,);
B(B_F,FunCalcStatistics1!,,15,3,29,9,,?DprArray?AdiNumberOfElements?ArSum?ArMean?ArDeviation);
B(B_VAROUT,,rSum,29,5,31,7,);
B(B_VAROUT,,rMean,29,6,31,8,);
B(B_VAROUT,,rDeviation,29,7,31,9,);
B(B_COMMENT,,These functions show the read access from an input array using the GetPointer function.ø^Some statistical features are calculated from the input array arData [10.0; 20.0; 30.0],3,0,42,2,);
L(1,0,1,9);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

Example: FunCalcStatisticsInitArray1

POU header

All input and output variables used for programming this function have been declared in the POU header.The same POU header is used for all programming languages.

ST body

(* Calculate the number of elements from the pointer member diSize *)
diNumberOfElements:=prArray.diSize/INT_TO_DINT(Size_Of_Var(rCurrentElement) );
(* Copy the offset to an internal offset which can be increased later *)
diOffset:=prArray.diOffset;
(* Loop over all elements *)
for di := 1 to diNumberOfElements do
(* Calculate the current element di*10.0 *)
    rCurrentElement:=DINT_TO_REAL(di)*10.0;
(* Write the current element to the data to which the pointer refers *)
    Var_ToAreaOffs32(Var := rCurrentElement, 
                     iArea => prArray.iArea, 
                     diOffs => diOffset);
(* Increase the offset to the next element *)
    diOffset:=diOffset + INT_TO_DINT(Size_Of_Var(rCurrentElement));
end_for;

FunCalcStatistics1

The user-defined function FunCalcStatistics1 calculates statistics from the values being pointed at by prArray. Internally the instruction AreaOffs_ToVar is used to read from the external data's address areas.

ST body

(* Calculate the number of elements from the pointer member iSize *)
diNumberOfElements:=prArray.diSize/INT_TO_DINT(Size_Of_Var(rCurrentElement) );
(* Copy the offset to an internal offset which can be increased later *)
diOffset:=prArray.diOffset;
(* Loop over all elements *)
for di := 1 to diNumberOfElements do
(* Read the current element from the data to which the pointer refers *)
    rCurrentElement:=AreaOffs32_ToVar(iArea := prArray.iArea, diOffs := diOffset);
(* Calculate the sum and the square sum *)
    rSum:=rSum+rCurrentElement;
    rSquareSum:=rSquareSum+rCurrentElement*rCurrentElement; 
(* Increase the offset to the next element *)
    diOffset:=diOffset+INT_TO_DINT(Size_Of_Var(rCurrentElement));
end_for;
(* Final calculation of the additional statistical parameters *)
rNumberOfElements:=DINT_TO_REAL(diNumberOfElements);
rMean:=rSum/rNumberOfElements;
rDeviation:=SQRT(1.0/(rNumberOfElements-1.0)*rSquareSum);

Modified on: 2019-01-25Feedback on this pagePanasonic hotline