『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 10071|回复: 6

[流程系列] 关于485协议获取到设备状态二进制判断0和1的位置

[复制链接]

3

主题

37

帖子

682

积分

高级会员

Rank: 4

积分
682
金钱
645
HASS币
0
发表于 2021-3-11 22:46:34 | 显示全部楼层 |阅读模式

通过发送查询代码获取到设备(设备是8路DI输入)反馈的 16进制数据,转换位二进制后为,10000,从右到左依次数,第五位是1 ,代表第五个DI接口接收到信号。

msg.payload : string[5]
"10000"

清问NR中怎么判断第几路 接收到信号,然后反馈出来那些口有DI信号输入。 谢谢

这是关于8位二进制的每位是0或1的判断反馈。 新手,稿了很久,实在 没法,请大神帮忙。感激!


回复

使用道具 举报

3

主题

223

帖子

3047

积分

元老级技术达人

积分
3047
金钱
2819
HASS币
10
发表于 2021-3-12 00:14:20 | 显示全部楼层
都已经是string了 直接slice就行了
回复

使用道具 举报

3

主题

37

帖子

682

积分

高级会员

Rank: 4

积分
682
金钱
645
HASS币
0
 楼主| 发表于 2021-3-12 01:56:36 | 显示全部楼层
blindlight 发表于 2021-3-12 00:14
都已经是string了 直接slice就行了

太小白了。。。能否详细些,谢谢
回复

使用道具 举报

43

主题

412

帖子

3806

积分

元老级技术达人

积分
3806
金钱
3389
HASS币
136
发表于 2021-3-12 10:48:14 | 显示全部楼层
我前面搞了一下。可以实现的,方法不是最高效。但能用!你改改试试 222.png
[{"id":"c453fd7d.5b866","type":"inject","z":"a54dc4ab.4344e8","name":"","topic":"","payload":"255","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":290,"y":2540,"wires":[["57eb04ad.95accc"]]},{"id":"57eb04ad.95accc","type":"function","z":"a54dc4ab.4344e8","name":"根据输入取位","func":"var temp =(msg.payload)+flow.get('ss');\nvar msg1={};\nvar msg2={};\nvar msg3={};\nvar msg4={};\nvar msg5={};\nvar msg6={};\nvar msg7={};\nvar msg8={};\nvar msg9={};\n\n\nvar temps=("00000000" + temp.toString(2)).slice(-8)\n\nvar a,b,c,d,e,f,g\na=temps.charAt(0);\nb=temps.charAt(1);\nc=temps.charAt(2);\nd=temps.charAt(3);\ne=temps.charAt(4);\nf=temps.charAt(5);\ng=temps.charAt(6);\nh=temps.charAt(7);\n\nmsg1.payload=a;\nmsg2.payload=b;\nmsg3.payload=c;\nmsg4.payload=d;\nmsg5.payload=e;\nmsg6.payload=f;\nmsg7.payload=g;\nmsg8.payload=h;\nmsg9.payload=temp;\nreturn [msg1,msg2,msg3,msg4,msg5,msg6,msg7,msg8,msg9]","outputs":9,"noerr":0,"x":480,"y":2540,"wires":[["b0a5b046.895b"],["5083a47.1c5175c"],["e6826ee7.0f4f3"],["31a98290.8499fe"],["90f0f6ac.cdbbb8"],["1c7dc580.5babab"],["9268028a.f4a2f"],["e5cf7c7f.531a4"],["cefb6522.e53498"]]},{"id":"b0a5b046.895b","type":"debug","z":"a54dc4ab.4344e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":690,"y":2440,"wires":[]},{"id":"e5cf7c7f.531a4","type":"debug","z":"a54dc4ab.4344e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":1070,"y":2720,"wires":[]},{"id":"c3d7f9df.f6a818","type":"debug","z":"a54dc4ab.4344e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":810,"y":2760,"wires":[]},{"id":"5083a47.1c5175c","type":"debug","z":"a54dc4ab.4344e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":730,"y":2480,"wires":[]},{"id":"90f0f6ac.cdbbb8","type":"debug","z":"a54dc4ab.4344e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":910,"y":2600,"wires":[]},{"id":"e6826ee7.0f4f3","type":"debug","z":"a54dc4ab.4344e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":790,"y":2520,"wires":[]},{"id":"31a98290.8499fe","type":"debug","z":"a54dc4ab.4344e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":850,"y":2560,"wires":[]},{"id":"9268028a.f4a2f","type":"debug","z":"a54dc4ab.4344e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":1030,"y":2680,"wires":[]},{"id":"1c7dc580.5babab","type":"debug","z":"a54dc4ab.4344e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":970,"y":2640,"wires":[]},{"id":"43dc979c.4e5228","type":"inject","z":"a54dc4ab.4344e8","name":"","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":290,"y":2680,"wires":[["cefb6522.e53498"]]},{"id":"cefb6522.e53498","type":"change","z":"a54dc4ab.4344e8","name":"","rules":[{"t":"set","p":"ss","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":2660,"wires":[["c3d7f9df.f6a818"]]},{"id":"ee9056f1.814158","type":"comment","z":"a54dc4ab.4344e8","name":"通用状态数据获取-存入变量","info":"","x":300,"y":2420,"wires":[]}]



回复

使用道具 举报

3

主题

37

帖子

682

积分

高级会员

Rank: 4

积分
682
金钱
645
HASS币
0
 楼主| 发表于 2021-3-12 11:14:40 | 显示全部楼层
hunterfox 发表于 2021-3-12 10:48
我前面搞了一下。可以实现的,方法不是最高效。但能用!你改改试试

感谢您。 应该就是你发的这个!

但有个报错。导入不了


SyntaxError: JSON.parse: expected ',' or '}' after property value in object at line 1 column 493 of the JSON data

var temps=("00000000" +
回复

使用道具 举报

43

主题

412

帖子

3806

积分

元老级技术达人

积分
3806
金钱
3389
HASS币
136
发表于 2021-3-12 11:28:44 | 显示全部楼层
sea_dark 发表于 2021-3-12 11:14
感谢您。 应该就是你发的这个!

但有个报错。导入不了

我给附件你吧 flows.json (3.52 KB, 下载次数: 30)
回复

使用道具 举报

3

主题

37

帖子

682

积分

高级会员

Rank: 4

积分
682
金钱
645
HASS币
0
 楼主| 发表于 2021-3-12 13:39:56 | 显示全部楼层

搞定了。感谢你!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-11-21 23:40 , Processed in 1.138813 second(s), 31 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表