西门子S高级编程培训教材内部教材附录间接访问FC和FB参数.ppt
附录2:间接访问FC和FB参数,DB5 Temperature,FC21,参数的赋值只能通过符号地址,程序段 1:在 FC21中,声明Meas_Val 为一个数组。CALL FC 21 Meas_Val:=Temperature.sequence,使用复杂数据类型的功能调用,实例:向功能传递数组,复杂数据类型的参数传递,OB1,功能FC10,执行程序,CALL FC10On:=Value.FieldOff:=Q8.0,inOnARRAY1.10INToutOffBOOL.,.L#On8.=#Off.,OB1,BLD1=L20.0L5TLW21LP#DBX0.0TLD23UCFC10P#L 21.0P#Q8.0BLD2,L 堆栈(OB1),FieldARRAY1.10INT,LW 21,.,1,2,复杂的实参:L堆栈数据块,DB-No:5 区域交叉指针,DB5:Value,在L堆栈中建立指针,间接访问复杂数据类型,地址声明名称类型起始值注释0.0inMeas_ValARRAY1.8*4.0REAL32.0outSumREAL36.0outMean_ValREALin_out0.0tempDB_NumWORD,网络1:确定DB-No.和起始地址LP#Meas_Val/ACCU1读入指针地址LAR1/再加载到AR1;LW AR1,P#0.0/决定DB号T#DB_Num/并加载到温度变量;OPNDBDB_Num/打开DBLD AR1,P#2.0/决定区域指针LAR1/并加载到AR1;网络2:计算和L0.000000e+000/ACCU1清零(sum=0.0)L8/ACCU1读入计数值;ACCU2读入sum=0BEGN:TAK/ACCU1读入sum,ACCU2读入计数值ENT/ACCU3读入计数值 L DAR1,P#0.0/ACCU1读入场分量+R/ACCU1读入sum,ACCU2读入计数值+AR1P#4.0;/AR1增加4字节TAK/ACCU1读入循环计数,ACCU2读入sumLOOPBEGN;/循环计数减少,必要时跳转T#Sum/将sum传到#Sum,指针的参数传递,OB1,功能FC10,执行程序,CALL FC10On:=P#I 0.0 INT 10Off:=Q8.0,inOnANYoutOffBOOL.,.L P#On.=#Off.,OB1,BLD1=L20.0LW#16#1005TLW21L10TLW23L 0TLW25LP#I 0.0TLD27ACFC10P#L21P#Q8.0BLD2,L 堆栈(OB1),LW 21,.,1,2,POINTER和 ANY参数,10H 数据类型:05重复:10DB号:0 区域交叉指针:P#I0.0,.,在L堆栈中建立ANY指针,参数类型的参数传递,OB1,功能FC10,程序执行,CALL FC10On:=DB35Off:=Q8.0,in OnBLOCK_DBout OffBOOL.,.OPN#ON.=#Off.,BLD1=L20.0ACFC10P#4.3P#Q8.0BLD2,块参数:定时器,计数器BLOCK_xx,OB1,DB中的基本实参和常量的特点,OB1,功能FC10,程序执行,CALL FC10On_1:=I 0.1On_2:=DB5.DBX2.2Off:=DB5.DBX2.4,inOn_1BOOLinOn_2BOOLoutOffBOOl.,.A#On_1A#On_2=#Off.,OB1,BLD1=L20.0OPNDB5ADBX2.2=L20.1ACFC10P#I 0.1P#L 20.1P#L 20.2AL20.2OPNDB5=DBX2.4BLD2,L 堆栈(OB1),DB5,LB 20,.,.,.,.,.,0,1,.,0,0,0,1,0,1,0,0,.,.,1,2,3,DBB2,基本实参:常量在数据块中,0,A2.1练习:在FC中计算Date-and-Time参数,FC51,EN,ENO,IN_DT,Sec,QB13,Min,QB12,OB1_DATE_TIME,Hour,QB8,使用复杂数据类型的FB调用,实例:传递数组到功能块,FB17,复杂参数的赋值仅通过符号地址,程序段 1:CALL FB 17,DB 30 Meas_1:=Temperature.Cylinder Sum_1:=MD20 Sum_2:=MD30 Meas_2:=Temperature.Shaft,DB2 Temperature,间接访问输入/输出参数,AddressDeclarationNameTypeStart valueComment0.0inMeas_1ARRAY1.10*4.0REAL40.0outSum_1REAL0.000000e+00044.0outSum_2REAL0.000000e+00048.0in_outMeas_2ARRAY1.15*4.0in_outREAL54.0statDB_NumINT0,程序段 1:决定Meas_1的起始地址LAR1P#Meas_1/区域交叉指针加载到参数,/在AR1中无地址偏移(多重执行个体)TAR2/载入ACCU1中的地址偏移量+AR1/把地址偏移量加到AR1;/AR1现在指向背景DB中的参数/背景DB已经打开程序段 2:访问Meas_1L0.000000e+000/ACCU1清零(Summe=0.0)L10/ACCU1读入计数值;ACCU2读入Sum=0 BEGN:TAK/Sum在ACCU1,计数值在ACCU2ENT/ACCU3读入计数值 L DAR1,P#0.0/ACCU1中的域分量+R/Sum在ACCU1,ACCU2读入计数值+AR1P#4.0;/AR1增加4字节TAK/在ACCU1中循环计数,sum在ACCU2LOOPBEGN;/减循环计数,必要时跳转T#Sum_1/将sum传递到#Sum_1,间接访问输入/输出参数,AddressDeclarationNameTypeStart valueComment 0.0inMeas_1ARRAY1.10*4.0REAL40.0outSum_1REAL0.000000e+00044.0outSum_2REAL0.000000e+00048.0in_outMeas_2ARRAY1.15*4.0in_outREAL54.0statDB_NumINT0,网络3:决定Meas_2的起始地址LAR1P#Messung_2/POINTER读入区域交叉指针,不TAR2/读入ACCU1中地址偏移量,加到AR1;+AR1/AR1现在指向背景DB中的POINTERL W AR1,P#0.0/ACCU1从POINTER读取DB号 T#DB_Num/把DB号(或者0)设为静态变量 OPN DB#DB_Num/打开DB L D AR1,P#2.0/区域交叉指针加载到参数LAR1/AR1读入指针,AR1指向参数网络4:访问Meas_2L0.000000e+000/ACCU1请零(Sum=0.0)L15/ACCU1读入计数值;ACCU2读入Sum=0BEGN:TAK/Sum在ACCU1中,计数值在ACCU2中ENT/ACCU3读入计数值 L DAR1,P#0.0/域分量在ACCU1+R/Sum在ACCU1中,ACCU2读入计数值./.,“嵌套传递”参数,嵌套深度:S7-300:最多8 S7-400:最多16.嵌套传递决定于块、数据和参数类型:,调用FC调用FCFB调用FCFC调用FBFB调用FB数据类型ECPECPECPECP输入-输入 x-xx-x-xxxx输出-输出 x-xx-x-xx-输入/输出-输入 x-x-x-x-输入/输出-输出 x-x-x-x-输入/输出-输入/输出x-x-x-x-,E:基本数据类型C:复杂数据类型P:参数类型(定时器,计数器,块_x),FBs,FBs,FCs,OB,A2.2练习:在FB中计算Date-and-Time参数,FB63,EN,ENO,IN_DT,Sec,QB13,Min,QB12,OB1_DATE_TIME,Hour,QB8,FB83,IN_DT,0.0inIN_DT DATE_AND_TIMEDT#90-1-1-0:0:0.0outin_out8.0statDUMMYARRAY1.100*2.0statINT208.0statFB63_DTFB63,A2.3练习:在FB中计算In/Out参数,FB64,EN,ENO,IO_DT,Sec,QB13,Min,QB12,OB1_DATE_TIME,Hour,QB8,FB84,IN_DT,0.0inIN_DT DATE_AND_TIMEDT#90-1-1-0:0:0.0outin_out8.0statDUMMYARRAY1.100*2.0statINT208.0statFB64_DTFB64.,A2.1习题解答:在FC中访问DT参数,A2.2习题解答:在FB中访问DT参数,A2.3习题解答:在FB中访问I/O参数(第1部分),A2.3习题解答:在FB中访问I/O参数(第2部分),