Copies a variable value to an address area
This function copies the value of the variable at input Var to the address area defined by the memory area iArea and the 32-bit address offset diOffs. The size of the variable at input Var thereby determines the number of data copied.
Input
Variable whose value is copied to an address
Output
Value for the memory area1)
If iArea is a variable, then it must be located in the memory area DT or FL. This should be checked using a function that incorporates the FP Tool Library's functions Is_AreaDT or Is_AreaFL.
Offset for the starting 32-bit address of the memory area
The values for iArea and diOffs can be supplied via the function GetPointer32. The value for iArea has to lie in the DT orFL area.
Flag memory areas Available for FP7 only. |
SYS_MEMORY_AREA_R |
SYS_MEMORY_AREA_L |
|
SYS_MEMORY_AREA_X |
|
SYS_MEMORY_AREA_Y |
|
Flags |
SYS_MEMORY_AREA_WR |
Set value timer/counter |
SYS_MEMORY_AREA_SV |
Elapsed value timer/counter |
SYS_MEMORY_AREA_EV |
Data registers |
SYS_MEMORY_AREA_DT |
Link flags |
SYS_MEMORY_AREA_WL |
Link registers |
SYS_MEMORY_AREA_LD |
File registers |
SYS_MEMORY_AREA_FL |
Input registers |
SYS_MEMORY_AREA_WX |
Output registers |
SYS_MEMORY_AREA_WY |
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
bStart: BOOL:=FALSE;
(*activation*)
g_arArrayOut1: ARRAY [0..5] OF REAL:=[6(0.0)];
(*data field with cumulative sum*)
g_arArrayIn1: ARRAY [0..5] OF REAL:=[10.0,20.0,30.0,40.0,50.0,60.0];
(*data field 1*)
CalcSum_Real1: CalcSum_Real;
(*instance of user function block*)
@'': @'';
END_VAR
When the variable bStart is set to TRUE, the function block CalcSum_REAL is carried out. It calculates the sum of all elements of the data field g_arArrayIn1 and writes the result to the data field g_arArrayOut1. In this way the first element of g_arArrayOut1 receives the first element of g_arArrayIn1. The second element of g_arArrayOut1 contains the sums of the first and second element of g_arArrayIn1.The third element of g_arArrayOut1 contains the sums of the first, second and third element of g_arArrayIn1.....
Remember that the function block CalcSum_REAL can calculate its function independently of the memory areas in which both data fields can be stored and independently of the number of elements in the data fields. If you wish to assign an address for the data field, you have to declare the data field in the global variable list.Both data fields must possess the same number of elements.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 7 ;
NETWORK_BODY
B(B_VARIN,,g_arArrayIn1,10,4,12,6,);
B(B_VARIN,,g_arArrayOut1,10,5,12,7,);
B(B_F,GetPointer32!,,12,4,19,6,,?D?C);
B(B_F,GetPointer32!,,12,5,19,7,,?D?C);
B(B_CONTACT,,bStart,5,3,7,5,);
B(B_FB,CalcSum_Real!,CalcSum_Real1,19,2,29,7,,?BEN?Bp32InputArray?Bp32OutputArray?AENO);
L(7,4,19,4);
L(1,4,5,4);
L(1,0,1,7);
END_NETWORK_BODY
END_NET_WORK
END_BODY
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_INPUT
p32ToDatafield: POINTER32;
(*pointer on the data field for calculation*)
END_VAR
VAR_OUTPUT
rSum: REAL:=0.0;
(*calculate sum*)
END_VAR
VAR
Sum_Operand: REAL:=0.0;
(*inernal calculation of the sum*)
In_Offs_Intern: DINT:=0;
(*internal offset*)
Idx: INT:=0;
(*index*)
END_VAR
Network 1–5:
here the initializations for calculating the sum that follows is dealt with.
copies value of an element from the input data field.
Network 7:
adds this value to the current sum.
Network 8:
copies current sum to an element of the output data field.
Network 9:
calculation of the offset for the next data field element of the input data field and output data field.
Network 10:
jump to the label (network 6) until all elements of the data field have been processed.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 5 ;
NETWORK_BODY
B(B_F,Is_AreaDT!,,12,0,18,2,,?D?C);
B(B_VARIN,,p32ToDatafield.iArea,9,1,11,3,);
B(B_F,Is_AreaFL!,,12,3,18,5,,?D?C);
B(B_F,@AND-2!,,19,1,24,4,NN,?D?D?C);
B(B_F,E_MOVE!,,29,0,35,4,,?DEN?D?AENO?C);
B(B_VARIN,,FALSE,27,2,29,4,);
B(B_VAROUT,,ENO,35,2,37,4,);
B(B_RETURN,,,36,1,38,3,);
L(12,2,12,4);
L(12,1,12,2);
L(11,2,12,2);
L(18,1,18,2);
L(18,2,19,2);
L(18,3,18,4);
L(18,3,19,3);
L(35,2,36,2);
L(24,2,29,2);
L(1,0,1,5);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 2 ;
NETWORK_BODY
B(B_VARIN,,p32ToDatafield.diOffset,18,0,20,2,);
B(B_VAROUT,,In_Offs_Intern,20,0,22,2,);
L(1,0,1,2);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 2 ;
NETWORK_BODY
B(B_VARIN,,0.0,18,0,20,2,);
B(B_VAROUT,,rSum,20,0,22,2,);
L(1,0,1,2);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 2 ;
NETWORK_BODY
B(B_VARIN,,1,18,0,20,2,);
B(B_VAROUT,,Idx,20,0,22,2,);
L(1,0,1,2);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := Lbl1: ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 4 ;
NETWORK_BODY
B(B_F,AreaOffs32_ToVar!,,17,0,27,4,,?DiArea?DdiOffs?C@'Var');
B(B_VARIN,,p32ToDatafield.iArea,15,1,17,3,);
B(B_VAROUT,,Sum_Operand,27,1,29,3,);
B(B_VARIN,,In_Offs_Intern,15,2,17,4,);
L(1,0,1,4);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 3 ;
NETWORK_BODY
B(B_F,@ADD-2!,,17,0,22,3,,?D?D?C);
B(B_VARIN,,rSum,15,0,17,2,);
B(B_VARIN,,Sum_Operand,15,1,17,3,);
B(B_VAROUT,,rSum,22,0,24,2,);
L(1,0,1,3);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 3 ;
NETWORK_BODY
B(B_F,Size_Of_Var!,,17,1,24,3,,?D?C);
B(B_VARIN,,Sum_Operand,15,1,17,3,);
B(B_F,@ADD-2!,,32,0,37,3,,?D?D?C);
B(B_VARIN,,In_Offs_Intern,30,0,32,2,);
B(B_VAROUT,,In_Offs_Intern,37,0,39,2,);
B(B_F,INT_TO_DINT!,,24,1,32,3,,?D?C);
L(1,0,1,3);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 5 ;
NETWORK_BODY
B(B_F,@LT-2!,,13,1,18,4,,?D?D?C);
B(B_VARIN,,p32ToDatafield.diSize,11,2,13,4,);
B(B_F,E_ADD-2!,,22,0,28,5,,?DEN?D?D?AENO?C);
B(B_VARIN,,1,20,3,22,5,);
B(B_VAROUT,,Idx,28,2,30,4,);
B(B_VARIN,,Idx,20,2,22,4,);
B(B_JUMP,,Lbl1,28,1,30,3,);
B(B_VARIN,,Idx,3,1,5,3,);
B(B_F,INT_TO_DINT!,,5,1,13,3,,?D?C);
L(18,2,22,2);
L(1,0,1,5);
END_NETWORK_BODY
END_NET_WORK
END_BODY
Further example projects (directory "Samples" of FPWIN Pro installation):