赞
踩
用途:用于调试串口接收数据的正确性
'——————————————————————— '驱动脚本:采集函数脚本,MCGS将定时调用这个函数 '这个函数需要完成从设备获取数据,并将数据根据协议 '进行解析,最后赋值到相应通道上的功能。 '这部分是注释,请在下面编辑采集脚本的内容: '——————————————————————— DIM Return as INTEGER dim ByteReg as byte dim READ(512) as byte dim i as integer dim RecCount as integer DIM LenStr as STRING DIM DataPackStr as STRING DIM PackStr as STRING DIM PackHEX as STRING dim 时间 as integer DIM TimeStr as STRING 时间=!TimeGetCurrentTime() TimeStr=!TimeI2Str(时间,"%Y-%m-%d %H:%M:%S") i=1 RecCount = 0 PackHEX ="" PackStr ="" DataPackStr ="" WHILE(i<=512) Return =!DevReadByte(ByteReg,10) IF Return <0 THEN Return=!DevReadByte(ByteReg,10) IF Return = 0 THEN READ[i] = ByteReg IF ByteReg<=15 THEN PackHEX =PackHEX +"0"+!I2Hex(ByteReg)+" " ELSE PackHEX =PackHEX +!I2Hex(ByteReg)+" " ENDIF IF (i mod 26)=0 THEN PackHEX=PackHEX+!Chr(13)+!Chr(10) RecCount = RecCount + 1 i=i+1 ELSE i=513 ENDIF ENDWHILE IF RecCount =0 THEN exit LenStr = !Format(RecCount ,"000") !ByteArr2Str(READ,PackStr ,RecCount ) DataPackStr ="" DataPackStr = "[Time:"+TimeStr+" Len:"+LenStr +"] "+PackStr !Trace(DataPackStr ) !SetStrDataValueByName("Rec_Str",DataPackStr) DataPackStr ="" DataPackStr = "[Time:"+TimeStr+" Len:"+LenStr +"] "+PackHEX !Trace(DataPackStr ) !SetStrDataValueByName("HEX_Str",DataPackStr) 写事件=1-写事件 !SetIntChannelValueByName("写事件",写事件)
源码文件gitee地址
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。