新闻中心
PRESS CENTER本文主要实现的功能是:使用EG系列网关,实现串口与网口的自定义数据收发功能,并支持串口到网口之间的双向数据透传。EG系列网关可通过串口(如RS485/RS232)接收或发送自定义协议数据,同时通过以太网接口(TCP/MQTT/UDP)与上位机或其他网络设备进行数据交互。透传功能确保串口侧的数据可实时、可靠地转发至网络侧,反之亦然,满足工业物联网场景下多协议、多接口互联的通信需求。整体方案具备高灵活性与可扩展性,适用于数据采集、远程监控及设备联网等应用。
场景一:串口自定义数据收发
1. 使用注入节点构造数据
EG系列网关通过串口1实现自定义数据格式的发送与接收(使用串口调试软件模拟串口设备):
下行发送(网关 → 串口设备):EG系列网关向串口1发送一串十六进制数据:01 02 03 04 05 06 0A 0B ,使用注入节点发送数据,在配置注入节点时,数据类型设置为“二进制流”(Buffer),数据以十进制格式输入,对应为:1, 2, 3, 4, 5, 6, 10, 11。
此处为语雀内容卡片,点击链接查看:https://iotrouter.yuque.com/zn3vdn/eg8000/lg97tbt1ma1nfzb3#z8HWp
上行接收(串口设备 → 网关):EG系列网关从串口1接收数据,使用调试节点打印串口工具发送的数据。
[{"id":"2b4704f7922fabce","type":"serial port","z":"a3d0b3056469a324","name":"","serial":"3d7d723f9d24c89e","x":370,"y":260,"wires":[["f1b38d12ef17afda"]]},{"id":"92173440eff8d025","type":"inject","z":"a3d0b3056469a324","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[1,2,3,4,5,6,10,11]","payloadType":"bin","x":150,"y":260,"wires":[["2b4704f7922fabce"]]},{"id":"f1b38d12ef17afda","type":"debug","z":"a3d0b3056469a324","name":"调试 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":260,"wires":[]},{"id":"3d7d723f9d24c89e","type":"serial config","name":"","serialport":"/dev/ttyAS3","serialportname":"RS485-1","baudrate":"9600","databits":"8","stopbits":"1","parity":"none","timeout":"50","reqtimeout":"1000"}] |
2. 使用函数计算节点构造数据
除了使用注入节点发送自定义数据外,还可通过函数计算节点灵活构造和封装待发送的数据报文。配置如下:在函数计算节点中编写JavaScript代码,将目标数据(十六进制报文)以数组形式按字节定义,并封装为Buffer对象输出。例如,发送数据 01 02 03 04 05 06 0A 0B,可表示为:
msg.payload = Buffer.from([0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x0A, 0x0B]); return msg; |
[{"id":"9b2fbc4223a8a405","type":"inject","z":"a3d0b3056469a324","name":"","props":[{"p":"payload"},{"p":"topic","vt":tr"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":260,"wires":[["ea7b6a1481b2cb8d"]]},{"id":"ea7b6a1481b2cb8d","type":"function","z":"a3d0b3056469a324","name":"函数计算 1","func":"msg.payload = Buffer.from([0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x0A, 0x0B]);\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":350,"y":260,"wires":[["2b4704f7922fabce"]]},{"id":"2b4704f7922fabce","type":"serial port","z":"a3d0b3056469a324","name":"","serial":"3d7d723f9d24c89e","x":590,"y":260,"wires":[["eeb20e704fcb6bfe"]]},{"id":"eeb20e704fcb6bfe","type":"debug","z":"a3d0b3056469a324","name":"调试 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":810,"y":260,"wires":[]},{"id":"3d7d723f9d24c89e","type":"serial config","name":"","serialport":"/dev/ttyAS3","serialportname":"RS485-1","baudrate":"9600","databits":"8","stopbits":"1","parity":"none","timeout":"50","reqtimeout":"1000"}] |
场景二:网口(TCP协议)自定义数据收发
1. 网关作为TCP客户端
与场景1的串口自定义收发流程类似,若要实现网口(TCP)的自定义数据收发,只需将原流程中的串口节点替换为TCP客户端节点,连接TCP服务器即可(使用网络调试助手模拟TCP服务器)。
[{"id":"ae1690e73aa50bb9","type":"inject","z":"a3d0b3056469a324","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[1,2,3,4,5,6,10,11]","payloadType":"bin","x":250,"y":420,"wires":[["2a19998cda5f16e7"]]},{"id":"db64c73423c1f330","type":"debug","z":"a3d0b3056469a324","name":"调试 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":420,"wires":[]},{"id":"2a19998cda5f16e7","type":"tcp request","z":"a3d0b3056469a324","name":"","server":"192.168.0.59","port":"9600","out":"sit","ret":"buffer","splitc":" ","newline":"","trim":false,"tls":"","x":460,"y":420,"wires":[["db64c73423c1f330"]]}] |
2. 网关作为TCP服务端
使用TCP IN节点工作在监听模式接收数据,通过TCP OUT节点来响应和发送数据。
[{"id":"1f53226ed4f3b785","type":"tcp in","z":"a3d0b3056469a324","name":"","server":"server","host":"","port":"502","datamode":"stream","datatype":"buffer","newline":"","topic":"","trim":false,"base64":false,"tls":"","x":270,"y":380,"wires":[["24484352918c8c59"]]},{"id":"6176128689f6e641","type":"tcp out","z":"a3d0b3056469a324","name":"","host":"","port":"","beserver":"reply","base64":false,"end":false,"tls":"","x":490,"y":300,"wires":[]},{"id":"cce25820a104d510","type":"inject","z":"a3d0b3056469a324","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[1, 2, 3, 4, 5, 6, 10, 11]","payloadType":"bin","x":270,"y":300,"wires":[["6176128689f6e641"]]},{"id":"24484352918c8c59","type":"debug","z":"a3d0b3056469a324","name":"调试 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":490,"y":380,"wires":[]}] |
场景三:数据透传
1. 串口到TCP(MQTT同理)
这里以EG系列网关的RS485-1口与TCP服务器进行数据透传为例:
此处为语雀视频卡片,点击链接查看:见文末
2. TCP到MQTT
这里以EG系列网关TCP与MQTT数据透传为例:
详细见:https://iotrouter.yuque.com/zn3vdn/eg8000/rct9apxmetko92v4