作者 | 主题 |
---|---|
steven.lee 侠士 经验值:1302 发帖数:175 精华帖:2 |
楼主 2021-05-16 10:56:48
主题:批量WORD转REAL SCL程序 把一个DB块中的WORD数据类型转成REAL类型存于另一个DB块中,程序已经仿真验证。 FB块程序如下 VAR_INPUT DB_Source_Num { ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'} : DInt; DB_Source_Address { ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'} : DInt; DB_Target_Num { ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'} : DInt; DB_Target_Address { ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'} : DInt; END_VAR VAR "Array" { ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'} : Array[0..7] of Word; END_VAR VAR_TEMP i : DInt; END_VAR BEGIN FOR #i := 0 TO 7 DO #Array[#i]:= PEEK_WORD(area := 16#84, dbNumber := #DB_Source_Num, byteOffset := #DB_Source_Address + #i * 2);
POKE(area := 16#84, dbNumber := #DB_Target_Num, byteOffset := #DB_Target_Address + #i * 4, value := REAL_TO_DWORD(DINT_TO_REAL(DWORD_TO_DINT(#Array[#i] AND DW#16#FFFF)))); END_FOR; END_FUNCTION_BLOCK OB1程序如下 ORGANIZATION_BLOCK "Main" TITLE = "Main Program Sweep (Cycle)" { S7_Optimized_Access := 'TRUE' } VERSION : 0.1 BEGIN "WTR_DB"(DB_Source_Num:=1, DB_Target_Num:=2); END_ORGANIZATION_BLOCK 仿真结果如下: |