Fornisce informazioni sul puntatore
La funzione GetPointer32 fornisce informazioni sul puntatore 32 bit delle variabili in un tipo unità dati (DUT) predefinito del tipo di dato POINTER32 che può essere utilizzato dalle funzioni o dai Function Block. Con tali informazioni sul puntatore e le funzioni corrispondenti del puntatore, le funzioni o i Function Block possono direttamente leggere da o scrivere nell'area indirizzi dei dati esterni.
Ingresso
Variabile di ingresso di un tipo di dato qualsiasi che deve trovarsi nell'area di memoria DT, FL o Y.
Uscita
Le informazioni sul puntatore della variabile di ingresso.
Le funzioni definite dall'utente o i Function Block definiti dall'utente possono utilizzare le informazioni sul puntatore come segue:
L'elemento del puntatore iSize può specificare il numero di valori, ossia (numero di elementi = Pointer.iSize / Size_Of_Var (DataElement))
Con le funzioni corrispondenti del puntatore AreaOffs32_ToVar e Var_ToAreaOffs32 e con gli elementi del puntatore iArea e diOffset, potete direttamente leggere da o scrivere nell'area indirizzi dei dati esterni.
Con le istruzioni dell'area di memoria Is_AreaDT o Is_AreaFL e con le istruzioni dell'indirizzo AdrDT_Of_Offs32 o AdrFL_Of_Offs32, potete anche utilizzare le istruzioni FP con le aree indirizzi dei dati esterni.
La variabile di ingresso deve trovarsi nell'area di memoria DT o FL per le seguenti ragioni:
perché le istruzioni dell'area di memoria Is_AreaDT o Is_AreaFL e le istruzioni dell'indirizzo AdrDT_Of_Offs32 o AdrFL_Of_Offs32 funzionano unicamente con queste aree di memoria.
perché le istruzioni del puntatore AreaOffs32_ToVar e Var_ToAreaOffs32 funzionano correttamente solo con queste aree di memoria.
Questa istruzione sostituisce l'istruzione AreaOffs_OfVar.
Tutte le variabili di ingresso e uscita utilizzate per programmare questa funzione sono state dichiarate nell'intestazione del POU. La stessa intestazione del POU è utilizzata per tutti i linguaggi di programmazione.
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
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
Tutte le variabili di ingresso e uscita utilizzate per programmare questa funzione sono state dichiarate nell'intestazione del POU.La stessa intestazione del POU è utilizzata per tutti i linguaggi di programmazione.
(* 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;
La funzione definita dall'utente FunCalcStatistics1 calcola le statistiche dai valori indicati da prArray. Internamente, l'istruzione AreaOffs_ToVar viene utilizzata per leggere dalle aree indirizzi dei dati esterni.
(* 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);