将地址的内容复制到带有16位偏移量的变量
此函数将通过变量Var的大小定义的字数从由内存区Area和地址偏移量Offs定义的地址复制到变量Var。
输入
内存区的值1)
如果Area为变量,则必须位于内存区DT或FL。应使用包含FP工具库的函数Is_AreaDT或Is_AreaFL进行检查。
内存区的起始16位地址的偏移量
输出
地址的内容复制到的变量
通过函数GetPointer可提供Area和Offs的值。Area的值必须位于DT或FL区域中。
标志内存区 仅适用于FP7。 |
SYS_MEMORY_AREA_R |
SYS_MEMORY_AREA_L |
|
SYS_MEMORY_AREA_X |
|
SYS_MEMORY_AREA_Y |
|
标志 |
SYS_MEMORY_AREA_WR |
设置值定时器/计数器 |
SYS_MEMORY_AREA_SV |
经过值定时器/计数器 |
SYS_MEMORY_AREA_EV |
数据寄存器 |
SYS_MEMORY_AREA_DT |
链接继电器 |
SYS_MEMORY_AREA_WL |
链接数据寄存器 |
SYS_MEMORY_AREA_LD |
文件寄存器 |
SYS_MEMORY_AREA_FL |
输入寄存器 |
SYS_MEMORY_AREA_WX |
输出寄存器 |
SYS_MEMORY_AREA_WY |
在全局变量列表中,定义项目中所有POU都可以访问的变量。
此处分配变量g_arArrayIn1。也可以在程序Program_CalcSums的POU头中声明变量。
所有用于编程此函数的输入和输出变量已在POU头中声明。 所有编程语言使用相同的POU头。
R_EXTERNAL
WrongAreaArray: ARRAY [0..2] OF REAL:=[10.0,20.0,30.0];
END_VAR
VAR
start: BOOL:=FALSE;
RealArrayIn1: ARRAY [0..5] OF REAL:=[10.0,20.0,30.0,40.0,50.0,60.0];
RealArrayIn2: ARRAY [0..3,1..4] OF REAL:=[10.0,20.0,30.0,40.0,50.0,60.0,70.0,80.0,90.0,100.0,110.0,120.0,130.0,140.0,150.0,160.0];
RealArrayIn3: ARRAY [0..2,1..3,2..5] OF REAL:=[10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0];
RealSum1: REAL:=0.0;
(*Result: 210*)
RealSum2: REAL:=0.0;
(*Result: 1360*)
RealSum3: REAL:=0.0;
(*Result: 180*)
IsWrongArea: BOOL:=FALSE;
WrongAreaSum: REAL:=0.0;
CalcSum_Real1: CalcSum_REAL;
END_VAR
当变量bStart设置为TRUE时,执行功能块CalcSum_REAL。它计算数据区段g_arArrayIn1的所有元素的总和并将结果写入变量rRealSum1。
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 3 ;
NETWORK_BODY
B(B_COMMENT,,This program calculates the sum of all array elements of the input array In,3,1,38,2,);
L(1,0,1,3);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 10 ;
NETWORK_BODY
B(B_VARIN,,start,6,0,8,2,);
B(B_VAROUT,,RealSum1,36,4,38,6,);
B(B_VARIN,,RealArrayIn1,8,2,10,4,);
B(B_FB,CalcSum_REAL,CalcSum_Real1,25,2,36,8,,?BEN?BIn_Area?BIn_Offset?BNrOfIdx?AENO?ASum);
B(B_F,AreaOffs_OfVar,,10,1,22,5,,?D@'Var'?CArea?COffs);
B(B_F,Elem_OfArray1D,,10,5,22,8,,?DArray1D?CNrOfElem1);
B(B_COMMENT,,10+20+30+40+50+60,26,8,35,9,);
B(B_COMMENT,,=,36,8,38,9,);
B(B_COMMENT,,210.0,39,8,43,9,);
B(B_COMMENT,,if (Enable==TRUE):,15,8,25,9,);
L(25,1,25,4);
L(8,1,25,1);
L(24,3,24,5);
L(23,4,23,6);
L(24,5,25,5);
L(10,3,10,7);
L(22,3,24,3);
L(22,4,23,4);
L(22,7,25,7);
L(23,6,25,6);
L(1,0,1,10);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 13 ;
NETWORK_BODY
B(B_VARIN,,start,6,0,8,2,);
B(B_VAROUT,,RealSum2,36,4,38,6,);
B(B_VARIN,,RealArrayIn2,8,2,10,4,);
B(B_FB,CalcSum_REAL,CalcSum_Real1,25,2,36,8,,?BEN?BIn_Area?BIn_Offset?BNrOfIdx?AENO?ASum);
B(B_F,Elem_OfArray1D,,10,5,22,8,,?DArray1D?CNrOfElem1);
B(B_COMMENT,,10+20+30+40+ø^50+60+70+80+ø^90+100+110+120+ø^130+140+150+160,26,8,35,12,);
B(B_COMMENT,,=,36,8,38,9,);
B(B_COMMENT,,1360.0,39,8,43,9,);
B(B_COMMENT,,if (Enable==TRUE):,15,8,25,9,);
L(25,1,25,4);
L(8,1,25,1);
L(24,3,24,5);
L(23,4,23,6);
L(24,5,25,5);
L(10,3,10,7);
L(22,7,25,7);
L(23,6,25,6);
L(1,0,1,13);
L(10,3,24,3);
L(10,4,23,4);
END_NETWORK_BODY
END_NET_WORK
END_BODY
所有用于编程此函数的输入和输出变量已在POU头中声明。 所有编程语言使用相同的POU头。
R_EXTERNAL
WrongAreaArray: ARRAY [0..2] OF REAL:=[10.0,20.0,30.0];
END_VAR
VAR
start: BOOL:=FALSE;
RealArrayIn1: ARRAY [0..5] OF REAL:=[10.0,20.0,30.0,40.0,50.0,60.0];
RealArrayIn2: ARRAY [0..3,1..4] OF REAL:=[10.0,20.0,30.0,40.0,50.0,60.0,70.0,80.0,90.0,100.0,110.0,120.0,130.0,140.0,150.0,160.0];
RealArrayIn3: ARRAY [0..2,1..3,2..5] OF REAL:=[10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0,10.0,0.0];
RealSum1: REAL:=0.0;
(*Result: 210*)
RealSum2: REAL:=0.0;
(*Result: 1360*)
RealSum3: REAL:=0.0;
(*Result: 180*)
IsWrongArea: BOOL:=FALSE;
WrongAreaSum: REAL:=0.0;
CalcSum_Real1: CalcSum_REAL;
END_VAR
网格1:
如果发送的数据区段不在DT或FL区域,功能块的ENO设置为FALSE且处理结束。
网格2:4:
此处处理用于计算后续总和的初始化。由于无法直接更改类别VAR_INPUT的变量,输入变量In_Offset必须复制到内部变量In_Offs_intern。
另请参阅:Var_ToAreaOffs
网格5:8:
总和计算的循环。
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 3 ;
NETWORK_BODY
B(B_COMMENT,,This program calculates the sum of all array elements of the input array In,3,1,38,2,);
L(1,0,1,3);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 10 ;
NETWORK_BODY
B(B_VARIN,,start,6,0,8,2,);
B(B_VAROUT,,RealSum1,36,4,38,6,);
B(B_VARIN,,RealArrayIn1,8,2,10,4,);
B(B_FB,CalcSum_REAL,CalcSum_Real1,25,2,36,8,,?BEN?BIn_Area?BIn_Offset?BNrOfIdx?AENO?ASum);
B(B_F,AreaOffs_OfVar,,10,1,22,5,,?D@'Var'?CArea?COffs);
B(B_F,Elem_OfArray1D,,10,5,22,8,,?DArray1D?CNrOfElem1);
B(B_COMMENT,,10+20+30+40+50+60,26,8,35,9,);
B(B_COMMENT,,=,36,8,38,9,);
B(B_COMMENT,,210.0,39,8,43,9,);
B(B_COMMENT,,if (Enable==TRUE):,15,8,25,9,);
L(25,1,25,4);
L(8,1,25,1);
L(24,3,24,5);
L(23,4,23,6);
L(24,5,25,5);
L(10,3,10,7);
L(22,3,24,3);
L(22,4,23,4);
L(22,7,25,7);
L(23,6,25,6);
L(1,0,1,10);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 13 ;
NETWORK_BODY
B(B_VARIN,,start,6,0,8,2,);
B(B_VAROUT,,RealSum2,36,4,38,6,);
B(B_VARIN,,RealArrayIn2,8,2,10,4,);
B(B_FB,CalcSum_REAL,CalcSum_Real1,25,2,36,8,,?BEN?BIn_Area?BIn_Offset?BNrOfIdx?AENO?ASum);
B(B_F,Elem_OfArray1D,,10,5,22,8,,?DArray1D?CNrOfElem1);
B(B_COMMENT,,10+20+30+40+ø^50+60+70+80+ø^90+100+110+120+ø^130+140+150+160,26,8,35,12,);
B(B_COMMENT,,=,36,8,38,9,);
B(B_COMMENT,,1360.0,39,8,43,9,);
B(B_COMMENT,,if (Enable==TRUE):,15,8,25,9,);
L(25,1,25,4);
L(8,1,25,1);
L(24,3,24,5);
L(23,4,23,6);
L(24,5,25,5);
L(10,3,10,7);
L(22,7,25,7);
L(23,6,25,6);
L(1,0,1,13);
L(10,3,24,3);
L(10,4,23,4);
END_NETWORK_BODY
END_NET_WORK
END_BODY