📄 es16uh.zrg
字号:
prognum=csdreadrqt{j,1}
progtest=progtest+" "+substr(hex(prognum),3,2)
j=j+1
enddo
clear
@0,0 say progtest
set mode to 1
wait ""
endif
********************
return
endpro
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*对接收电能表数据作合理性判断和保存
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
procedure ReadAnswer
*initsio 0
strRecFlag="no"
receivebuf{1,100}=space(100)
crecbuff{1,100}=space(100)
*判断首起始符
i=0
m=1
j=0
do while i <> 068h
j = receives(receivebuf{1,1}, 20)
if j <> 0
i = receivebuf{1,1}
else
*clear
*@1,0 say "起始符不对"+str(i,1)
*wait ""
return
exit
endif
enddo
receivebuf{m,1} = 068h
m=m+1
*截取地址
j = receives(receivebuf{m,6}, 10)
if j<6
return
*clear
*@1,0 say "地址不对"+str(j,1)
*wait ""
endif
i = BCDtoNUM(receivebuf{m,6}, 0)
ctmpstr=str(i,12)
i=1
cmtnum=""
do while i<=12
cmtnum=cmtnum+str(val(substr(ctmpstr,i,1)),1)
i=i+1
enddo
m=m+6
*判断次起始符
j = receives(receivebuf{m,1}, 5)
i = receivebuf{m,1}
if i <> 068h
*clear
*@1,0 say "次起始符不对"+str(i,1)+",第"+str(m,1)+"个字节。"
*wait ""
return
endif
m=m+1
*判断控制码
j = receives(receivebuf{m,1}, 5)
i = receivebuf{m,1}
if i <> 081h .and. i<>0a1h .and. i<>0a2h .and. i<> 082h .and. i<>08ah.and.i<>08dh
*clear
*@1,0 say "控制码不对"+str(i,1)
*wait ""
return
endif
m=m+1
*判断数据长度
j = receives(receivebuf{m,1}, 5)
i =receivebuf{m,1}
nlen=i-2
m=m+1
*判断标识符
j = receives(receivebuf{m,1}, 5)
i= receivebuf{m,1}
if i<>nDataID1+51-int((ndataid1+51)/256)*256
*clear
*@1,0 say "标识符1不对"+str(i,1)
*wait ""
return
endif
m=m+1
j = receives(receivebuf{m,1}, 5)
i= receivebuf{m,1}
if i<>nDataID2+51-int((ndataid2+51)/256)*256
*clear
*@1,0 say "标识符2不对"+str(i,1)
*wait ""
return
endif
m=m+1
*获取数据
if nlen<>0
j = receives(receivebuf{m,nlen}, 5)
crecbuff{1,nlen}=receivebuf{m,nlen}
endif
m=m+nlen
*判断校验码
j = receives(receivebuf{m,1}, 5)
i = receivebuf{m,1}
j=CheckSum(receivebuf{1,m-1})
j=j-int(j/256)*256
if i <> j
*clear
*@1,0 say "校验码不对"+str(i,1)
*wait ""
return
endif
m=m+1
*判断结束符
j = receives(receivebuf{m,1}, 5)
i = receivebuf{m,1}
if i <> 22
*clear
*@1,0 say "结束符不对"+str(i,1)
*wait ""
return
endif
*置接收正常标志
strRecFlag="yes"
***********
if NPRORIGHT=0
progtest=""
set mode to 0
j=1
do while j<m+1
prognum=receivebuf{j,1}
progtest=progtest+" "+substr(hex(prognum),3,2)
j=j+1
enddo
clear
@0,0 say progtest
set mode to 1
wait ""
endif
**********
return
endpro
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
**向电能表发送写数据请求帧
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
procedure SendWrite
initsio 0 &&不改变波特率,仅清除串口接收缓冲区
crecbuff{1,100}=space(100)
receivebuf{1,100}=space(100)
*前导符
cSdReadRqt{1,2}=254
sends cSdReadRqt{1,2}
i=1
*起始符
cSdReadRqt{i,1}=104
i=i+1
*表号
cSdReadRqt{i,6}=szaddr{1,6}
i=i+6
*第二起始符
cSdReadRqt{i,1}=104
i=i+1
*控制码
cSdReadRqt{i,1}=val(corder[1])
i=i+1
*长度
cSdReadRqt{i,1}=val(corder[2])
i=i+1
*标识符
if equipment=0
if ndataid1<>0 .or. ndataid2<>0
cSdReadRqt{i,1}=nDataID1+51-int((ndataid1+51)/256)*256
i=i+1
cSdReadRqt{i,1}=nDataID2+51-int((ndataid2+51)/256)*256
i=i+1
endif
*密码
cSdReadRqt{i,4}=szpassword{1,4}
i=i+4
endif
*数据
if ndatalen>0
cSdReadRqt{i,ndatalen}=szdata{1,ndatalen}
i=i+ndatalen
endif
*校验码
j=CheckSum(cSdReadRqt{1,i-1})
j=j-256*int(j/256)
cSdReadRqt{i,1}=j
i=i+1
*结束符
cSdReadRqt{i,1}=22
*发送请求桢
sends cSdReadRqt{1,i}
****************
if NPRORIGHT=0
progtest=""
set mode to 0
j=1
do while j<i+1
prognum=csdreadrqt{j,1}
progtest=progtest+" "+substr(hex(prognum),3,2)
j=j+1
enddo
clear
@0,0 say progtest
set mode to 1
wait ""
endif
*****************
return
endpro
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*对写命令接收电能表数据作合理性判断和保存
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
procedure WriteAnswer
*initsio 0
strRecFlag="no"
crecbuff{1,100}=space(100)
receivebuf{1,100}=space(100)
*判断首起始符
i = 0
m = 1
jj = 1
* if ndataid1=0 .and. ndataid2=0 .and. corder[2]="00" .and. ( corder[1]="13" .or. corder[1]="09" .or. corder[1]="25" )
if ndataid1=0 .and. ndataid2=0 .and. ( corder[1]="13" .or. corder[1]="09" .or. corder[1]="25" )
do while i <> 068h
j = receives(receivebuf{1,1}, 30)
if j <> 0
i = receivebuf{1,1}
else
jj = jj + 1
if jj >4
exit
*esc直接退出
*clear
*@1,0 say "起始符不对"+str(i,1)
*wait ""
RETURN
endif
endif
enddo
else
do while i <> 068h
j = receives(receivebuf{1,1}, 30)
if j <> 0
i = receivebuf{1,1}
else
exit
*esc直接退出
*clear
*@1,0 say "起始符不对"+str(i,1)
*wait ""
RETURN
endif
enddo
endif
receivebuf{m,1} = 068h
m=m+1
*截取地址
***esczxh/04-04-06/延时0.5
j = receives(receivebuf{m,6}, 10)
i = BCDtoNUM(receivebuf{m,6}, 0)
ctmpstr=str(i,12)
i=1
cmtnum=""
do while i<=12
cmtnum=cmtnum+str(val(substr(ctmpstr,i,1)),1)
i=i+1
enddo
m=m+6
*判断次起始符
***esczxh/04-04-06/延时0.5
j = receives(receivebuf{m,1}, 5)
i = receivebuf{m,1}
if i <> 068h
*clear
*@1,0 say "次起始符不对"+str(i,1)+",第"+str(m,1)+"个字节。"
*wait ""
return
endif
m=m+1
*判断控制码
***esczxh/04-04-06/延时0.5
j = receives(receivebuf{m,1}, 5)
i = receivebuf{m,1}
if i <> 08ah .and. i<> 0aah .and. i <> 084h .and. i<>0a4h .and. i <> 08dh .and. i <> 08fh .and. i <> 089h .and. i <> 099h
*clear
*@1,0 say "控制码不对"+str(i,1)
*wait ""
return
endif
m=m+1
*判断数据长度
***esczxh/04-04-06/延时0.5
j = receives(receivebuf{m,1}, 5)
i = receivebuf{m,1}
nlen=i
m=m+1
if i<>0
j = receives(receivebuf{m,i}, 5)
i=receivebuf{m,2}
endif
m=m+nlen
*判断校验码
***esczxh/04-04-06/延时0.5
j = receives(receivebuf{m,1}, 5)
i = receivebuf{m,1}
j=CheckSum(receivebuf{1,m-1})
j=j-int(j/256)*256
if i <> j
*clear
*@1,0 say "校验码不对"+str(i,1)+"<>"+str(j,1)
*wait ""
return
endif
m=m+1
*判断结束符
***esczxh/04-04-06/延时0.5
j = receives(receivebuf{m,1}, 5)
i = receivebuf{m,1}
if i <> 22
*clear
*@1,0 say "结束符不对"+str(i,1)
*wait ""
return
endif
******************
i=m
******************
*置接收正常标志
szaddr{1,6}=0
szaddr=numtobcd(val(cmtnum),0)
m=scanbyte(szaddr{1,6},255)
if m>0
szaddr{m,7-m}=0
endif
strRecFlag="yes"
***********
if NPRORIGHT=0
progtest=""
set mode to 0
j=1
do while j<i+1
prognum=receivebuf{j,1}
progtest=progtest+" "+substr(hex(prognum),3,2)
j=j+1
enddo
clear
@0,0 say progtest
set mode to 1
wait ""
endif
***********
return
endpro
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*根据格式转换接收数据并显示
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
procedure XsData
do case
case nchangeformat=1 .or. nchangeformat=2
if ndataid1=032 .and. ndataid2=192 &&翻译运行状态字
j = crecBuff{1,1}
if j<51
j=j+256
endif
j=j - 51
ctmpstr=substr(hex(j),3,2)
clear
@0,0 say "运行状态字:"+ctmpstr
do showstatue
return
endif
if ndataid1=039 .and. ndataid2=192 &&翻译错误状态字
j = crecBuff{1,1}
if j<51
j=j+256
endif
j=j - 51
ctmpstr=substr(hex(j),3,2)
clear
@0,0 say "运行错误字:"+ctmpstr
do ShowError
return
endif
if ndataid1=040 .and. ndataid2=192 &&翻译信道状态字
j = crecBuff{1,1}
if j<51
j=j+256
endif
j=j - 51
ctmpstr=substr(hex(j),3,2)
clear
@0,0 say "信道状态字:"+ctmpstr
do channelstate
return
endif
do changeother
if len(trim(strxs))<=80
do xsdata1
else
do xsdata2
endif
case nchangeformat=3 .or. nchangeformat=4
if ndataid2=236
strdata = ""
i = BCDtoNUM(crecBuff{1, 1}, 33h)
jj = BCDtoNUM(crecBuff{2,3}, 33h)
strdata = strdata+str(jj,6)
if len(str(i,0))<2
strdata = strdata+".0"
else
strdata = strdata+"."
endif
strdata = strdata + str(i,0)
clear
@0,0 say "当前电量: " + strdata
wait ""
j = crecBuff{5,1}
if j<51
j=j+256
endif
j=j - 51
ctmpstr=substr(hex(j),3,2)
strdata=strdata+substr(hex(j),3,2)
clear
@0,0 say "运行错误字:"+ctmpstr
do ShowError
if ndataid1=016
j = crecBuff{6,1}
if i<51
j=j+256
endif
j=j - 51
ctmpstr=substr(hex(j),3,2)
strdata=strdata+substr(hex(j),3,2)
clear
@0,0 say "信道状态字:"+ctmpstr
do channelstate
endif
return
endif
do changepower
if tp_ver="tp600"
if len(trim(strxs))<=84
do xsdata1
else
do xsdata2
endif
else
if len(trim(strxs))<=80
do xsdata1
else
do xsdata2
endif
endif
case nchangeformat=5
do changerate
if len(trim(strxs))<=80
do xsdata1
else
do xsdata2
endif
endcase
return
endpro
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*若一屏能显示,用此显示方式
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
procedure XsData1
clear
@0,0 say trim(strxs)
@3,20 say ""
wait"" to cKeyChar
if asc(cKeyChar)=24
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -