汉枫HIS 实现LED屏幕本地传感器采集并显示「建议收藏」

汉枫HIS 实现LED屏幕本地传感器采集并显示「建议收藏」HF汉枫DTU,HIS脚本大小,大小不超过10K!要处理8个以上的参数值,就会特别吃力,需要不断的优化脚本!还是不建议用HF来实现本地转发,逻辑的处理对DTU的考验还是比较大的!同时里边还有大量的异或运算!以下脚本仅作

HF 汉枫 DTU ,HIS 脚本大小,大小不超过10K!要处理8个以上的参数值,就会特别吃力,需要不断的优化脚本!

还是不建议用HF来实现本地转发,逻辑的处理对DTU的考验还是比较大的!同时里边还有大量的异或运算!

以下脚本仅作参考和学习

cmd01=[0x03,0x03,0x00,0x00,0x00,0x01,0x85,0xE8]
cmd02=[0x04,0x03,0x00,0x00,0x00,0x01,0x84,0x5F]
cmd03=[0x05,0x03,0x01,0x05,0x00,0x01,0x94,0x73]
cmd04=[0x10,0x03,0x00,0x00,0x00,0x06,0xC6,0x89]

num=0
recvtime=0
mac=MAC
mac01=mac.stringHex()
DATA_S=[]
DATA_SP=[0xAA,0xAA]
DATA_R=[]
HEX_STRING="0123456789ABCDEF"
HEXY=0x38

#数字转acsii
FUNCTION tos1 (aaa)
    bbb = [0x30]
    IF(aaa==1)
        bbb = [0x31]
    END
    IF(aaa==2)
        bbb = [0x32]
    END
    IF(aaa==3)
       bbb = [0x33]
    END
    IF(aaa==4)
        bbb = [0x34]
    END
    IF(aaa==5)
        bbb = [0x35]
    END
    IF(aaa==6)
        bbb = [0x36]
    END
    IF(aaa==7)
        bbb = [0x37]
    END
    IF(aaa==8)
        bbb = [0x38]
    END
    IF(aaa==9)
        bbb = [0x39]
    END
    RETURN(bbb)
END

#10进制转为16进制 
FUNCTION tol1 (last)
    last1 = last/16
    last2 = last - ((last/16)*16)
    lastC1 = HEX_STRING.subString(last1,last1+1)
    lastC2 = HEX_STRING.subString(last2,last2+1)
    lastC = (lastC1+lastC2).stringHex()
    RETURN(lastC)
END

# LED屏展示风速值
FUNCTION toled1 (arg)
    tmp = arg
    ll = tmp.length()
    zhv = [0x30,0x2e,0x30]
    IF(ll>4)
         t0 = tmp.charAt(3)
         t1 = tmp.charAt(4)
         t = (t0*16+t1);
         ttx = t - 10 * (t/10)
         ttz = t/10
         tts0 = tos1(ttz)
         tts1 = tos1(ttx)
         zhv = tts0+[0x2e]+tts1
    END
    tou = [0xFE,0x98,0x00,0x16,0x97,0x37,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
    zh= [0x2F,0x00,0xFF,0xFF,0x03]+zhv
    last = HEXY^0x16^0x2F^0x00^0xFF^0xFF^0x03^ttz^0x2e^ttx
    lastCC = tol1(last)
    res = tou+zh+lastCC
    RETURN(res)
END

#LED屏展示风向,汉字编码GB2312
FUNCTION toled2 (arg)
    tmp = arg
    ll = tmp.length()
    zhv = [0xCE,0xB0,0xD6,0xAA]
    zhvo =0xCE^0xB0^0xD6^0xAA
    IF(ll>5)
       t0 = tmp.charAt(3)
       t1 = tmp.charAt(4)
       t = t0*16+t1
       IF(t==0)
         zhv = [0xd5,0xfd,0xB1,0xB1]
         zhvo =0xd5^0xfd^0xB1^0xB1
       END
       IF(t==1)
         zhv = [0xb6,0xab,0xd5,0xfd]
         zhvo =0xb6^0xab^0xd5^0xfd
       END
       IF(t==2)
         zhv = [0xd5,0xfd,0xb6,0xab]
         zhvo =0xd5^0xfd^0xb6^0xab
       END
        IF(t==3)
            zhv = [0xb6,0xab,0xc4,0xcf]
            zhvo =0xb6^0xab^0xc4^0xcf
        END
        IF(t==4)
            zhv = [0xD5,0xfd,0xc4,0xcf]
            zhvo =0xd5^0xfd^0xc4^0xcf
        END
        IF(t==5)
            zhv = [0xce,0xf7,0xc4,0xcf]
            zhvo =0xce^0xf7^0xc4^0xcf
        END
        IF(t==6)
            zhv = [0xd5,0xfd,0xce,0xf7]
            zhvo =0xd5^0xfd^0xce^0xf7
        END
        IF(t==7)
            zhv = [0xd5,0xfd,0xb1,0xb1]
            zhvo =0xd5^0xfd^0xb1^0xb1
        END
    END
    tou = [0xFE,0x98,0x00,0x17,0x97,0x37,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
    zh= [0x30,0x00,0xFF,0xFF,0x04]+zhv
    last = HEXY^0x17^0x30^0x00^0xFF^0xFF^0x04^zhvo
    lastCC = tol1(last)
    res = tou+zh+lastCC
    RETURN(res)
END

#展示雨量数据
FUNCTION toled3 (arg)
   tmp = arg
   ll = tmp.length()
   zhv = [0x30,0x2e,0x30]
   IF(ll>6)
        t0 = tmp.charAt(3)
        t1 = tmp.charAt(4)
        t = (t0*16+t1);
        ttx = t - 10 * (t/10);
        ttz = t/10
        tts0 = tos1(ttz)
        tts1 = tos1(ttx)
        zhv = tts0+[0x2e]+tts1
   END
   tou = [0xFE,0x98,0x00,0x16,0x97,0x37,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
   zh= [0x32,0x00,0xFF,0xFF,0x03]+zhv
   last = HEXY^0x16^0x32^0x00^0xFF^0xFF^0x03^ttz^0x2e^ttx
   lastCC = tol1(last)
   res = tou+zh+lastCC
   RETURN(res)
END

#展示温度和湿度
FUNCTION toled4 (arg)
   tmp = arg
   ll = tmp.length()
   wd = [0x30,0x30,0x2e,0x30]
   wdor = 0x30^0x30^0x2e^0x30
   sd = [0x30,0x30,0x2e,0x30]
   sdor = 0x30^0x30^0x2e^0x30
   IF(ll>6)
        t0 = tmp.charAt(3)
        t1 = tmp.charAt(4)
        t = (t0*16+t1)
        ttx = t - 10 * (t/10)
        ttz1 = t/10 - (t/100)*10
        ttz2 = t/100
        tts0 = tos1(ttx)
        tts1 = tos1(ttz1)
        tts2 = tos1(ttz2)
        wd = tts2+tts1+[0x2e]+tts0
        wdor = ttz2^ttz1^0x2e^ttx
        at0 = tmp.charAt(5)
        at1 = tmp.charAt(6)
        at =  at0*16 + at1d
        attx = at - 10 * (at/10)
        attz1 = at/10 - (at/100)*10
        attz2 = at/100
        atts0 = tos1(attx)
        atts1 = tos1(attz1)
        atts2 = tos1(attz2)
        sd = atts2+atts1+[0x2e]+atts0
        sdor = attz2^attz1^0x2e^attx
   END
    tou = [0xFE,0x98,0x00,0x20,0x97,0x37,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
    wd1 = [0x29,0x00,0xFF,0xFF,0x04] + wd
    sd1 = [0x2A,0x00,0xFF,0xFF,0x04] + sd
    last = HEXY^0x20^0x29^0x00^0xFF^0xFF^0x04^wdor^0x2A^0x00^0xFF^0xFF^0x04^sdor
    lastCC = tol1(last)
    res = tou+wd1+sd1+lastCC
    RETURN(res)
END

#展示光照
FUNCTION toled5 (arg)
     tmp = arg
     ll = tmp.length()
     sun = [0x30,0x30,0x30,0x30,0x30,0x30]
     sunor = 0x30^0x30^0x30^0x30^0x30^0x30
     IF(ll>10)
         st0 = tmp.charAt(8)
         st1 = tmp.charAt(9)
         st2 = tmp.charAt(10)
         st = st0 * 65535 + st2*256 + st3
         sww2 = st  / 100000
         ww2 = (st -  (sww2*100000) ) / 10000
         qw2 = (st - (sww2*100000) - (ww2*10000) ) / 1000
         bw2 = (st - (sww2*100000) - (ww2*10000) - (qw2*1000) )/100
         sw2 = (st - (sww2*100000) - (ww2*10000) - (qw2*1000) - bw2*100) )/10
         gw2 = st -  (sww2*100000) - (ww2*10000) - (qw2*1000) - (bw2*100) - (sw2*10)
         sww1 = tos1(sww2)
         ww1 = tos1(ww2)
         qw1 = tos1(qw2)
         bw1 = tos1(bw2)
         sw1 = tos1(sw2)
         gw1 = tos1(gw2)
         sun = sww1+ww1+qw1+bw1+sw1+gw1
         sunor= ( 0x30 + sww2 ) ^ ( 0x30 + ww2 ) ^ ( 0x30 + qw2 ) ^ ( 0x30 + bw2 ) ^ ( 0x30 + sw2 ) ^ ( 0x30 + gw2 )
    END
    tou = [0xFE,0x98,0x00,0x19,0x97,0x37,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
    sun1= [0x31,0x00,0xFF,0xFF,0x06] + sun
    last = HEXY^0x19^0x31^0x00^0xFF^0xFF^0x06^sunor
    lastCC = tol1(last)
    res = tou+sun1+lastCC
    RETURN(res)
END

#展示二氧化碳 和 固定气压值,气压值为101Kpa
FUNCTION toled6 (arg)
    tmp = arg
    ll = tmp.length()
    # 1
    co2 = [0x30,0x30,0x30,0x30]
    coor = 0x30^0x30^0x30^0x30
    IF(ll>12)
     ct0 = tmp.charAt(11)
     ct1 = tmp.charAt(12)
     ct = ct0 *256 + ct1
     cq2 = ct/1000
     cb2 = (ct - (cq2*1000) ) /100
     cs2 = (ct - (cq2*1000) - (cb2*100) ) /10
     cg2 = ct - (cq2*1000) - (cb2*100) - (cs2*10)
     cq1 = tos1(cq2)
     cb1 = tos1(cb2)
     cs1 = tos1(cs2)
     cg1 = tos1(cg2)
     co2 = cq1+cb1+cs1+cg1
     coor = cq2^cb2^cs2^cg2
    END
    tou = [0xFE,0x98,0x00,0x1f,0x97,0x37,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00]
    co21= [0x2B,0x00,0xFF,0xFF,0x04] + co2
    qy1= [0x2C,0x00,0xFF,0xFF,0x03,0x31,0x30,0x31]
    last = HEXY^0x1f^0x2B^0x00^0xFF^0xFF^0x04^coor^0x1F
    lastCC = tol1(last)
    res = tou+co21+qy1+lastCC
    RETURN(res)
END

#串口接收
RECV UART uart
	IF(num==1 || num==3 || num==5 || num==7)
		DATA=INPUT
		DATA_R=DATA
		DATA_S=DATA_S+DATA_SP+DATA
	END
END

#定时器处理
TIMER HeartBeat 1000
	t=SYSTIME
	t=t-recvtime
	IF(t>4*1000)
		num=num+1
		IF(num==1)
			SEND(UART,uart,cmd01)
		END
		IF(num==3)
			SEND(UART,uart,cmd02)
		END
		IF(num==5)
			SEND(UART,uart,cmd03)
		END
		IF(num==7)
			SEND(UART,uart,cmd04)
		END

        IF(num==2)
            mydata3 = toled1(DATA_R)
			SEND(UART,uart,mydata3)
			DATA_R=[]
		END
        IF(num==4)
            mydata3 = toled2(DATA_R)
            SEND(UART,uart,mydata3)
            DATA_R=[]
        END
        IF(num==6)
            mydata3 = toled3(DATA_R)
			SEND(UART,uart,mydata3)
			DATA_R=[]
		END
		IF(num==8)
		    mydata4 = toled4(DATA_R)
            SEND(UART,uart,mydata3)
        END
        IF(num==9)
			mydata5 = toled5(DATA_R)
            SEND(UART,uart,mydata5)
        END
        IF(num==10)
			mydata6 = toled6(DATA_R)
            SEND(UART,uart,mydata6)
        END
        # 通过MQTT发送出去
		IF(num==12)
			num=0
			mydata = DATA_SP+mac01+DATA_S
			mydata2 = mydata.hexString()
			SEND(SOCK,A,mydata2)
			DATA_S=[]
		END
		recvtime=SYSTIME
	END
END

感谢您的支持,写的文章如对您有所帮助,开源不易,请您打赏,谢谢啦~

 汉枫HIS 实现LED屏幕本地传感器采集并显示「建议收藏」

今天的文章汉枫HIS 实现LED屏幕本地传感器采集并显示「建议收藏」分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/71283.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注