对接Modbus协议示例
插件图片
对接Modbus协议示例
功能介绍

通过Node-RED规则引擎的方式接入MODBUS协议的设备示例

视频讲解:ThingsPanel对接ModBus设备【通过规则引擎】_哔哩哔哩_bilibili

JSON代码:

[
  {
    "id": "de43fb9fa12e01f7",
    "type": "tab",
    "label": "modbus测试"
  },
  {
    "id": "615e8531e8d15b02",
    "type": "modbus-flex-getter",
    "z": "de43fb9fa12e01f7",
    "name": "",
    "showStatusActivities": false,
    "showErrors": false,
    "logIOActivities": false,
    "server": "dc1ec22ef7dc9999",
    "useIOFile": false,
    "ioFile": "",
    "useIOForPayload": false,
    "emptyMsgOnFail": false,
    "keepMsgProperties": false,
    "x": 750,
    "y": 780,
    "wires": [
      [
        "6182c8cc4812806a",
        "3ec6c57aeedb4a1a"
      ],
      [
        "40c865f0a037f257"
      ]
    ]
  },
  {
    "id": "6e67b2706fd263b8",
    "type": "modbus-flex-write",
    "z": "de43fb9fa12e01f7",
    "name": "",
    "showStatusActivities": false,
    "showErrors": false,
    "server": "dc1ec22ef7dc9999",
    "emptyMsgOnFail": false,
    "keepMsgProperties": false,
    "x": 1090,
    "y": 100,
    "wires": [
      [],
      [
        "ecf9bd4af996b17c"
      ]
    ]
  },
  {
    "id": "777b44a9d13c4e3c",
    "type": "function",
    "z": "de43fb9fa12e01f7",
    "name": "fc3 1[0~9]",
    "func": "msg.payload = {\n    'fc': 3,\n    'unitid': 1,\n    'address': 0,\n    'quantity': 3\n};\nreturn msg;",
    "outputs": 1,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 560,
    "y": 780,
    "wires": [
      [
        "615e8531e8d15b02"
      ]
    ]
  },
  {
    "id": "c9db275f7c2c5456",
    "type": "inject",
    "z": "de43fb9fa12e01f7",
    "name": "读取设备值",
    "props": [
      {
        "p": "payload"
      },
      {
        "p": "topic",
        "vt": "str"
      }
    ],
    "repeat": "",
    "crontab": "",
    "once": false,
    "onceDelay": 0.1,
    "topic": "",
    "payload": "",
    "payloadType": "date",
    "x": 395,
    "y": 780,
    "wires": [
      [
        "777b44a9d13c4e3c"
      ]
    ]
  },
  {
    "id": "40c865f0a037f257",
    "type": "modbus-response",
    "z": "de43fb9fa12e01f7",
    "name": "",
    "registerShowMax": 20,
    "x": 980,
    "y": 786,
    "wires": []
  },
  {
    "id": "41d0f3a3c06f266c",
    "type": "random",
    "z": "de43fb9fa12e01f7",
    "name": "",
    "low": "0",
    "high": "30",
    "inte": "true",
    "property": "payload",
    "x": 552,
    "y": 102,
    "wires": [
      [
        "5ac13c69086958ef"
      ]
    ]
  },
  {
    "id": "1694c420152ad442",
    "type": "function",
    "z": "de43fb9fa12e01f7",
    "name": "fc16 1[0~9]",
    "func": "msg.payload = {\n    'value': msg.payload,\n    'fc': 16,\n    'unitid': 1,\n    'address': 0,\n    'quantity': 3\n};\nreturn msg;",
    "outputs": 1,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 881.5,
    "y": 100,
    "wires": [
      [
        "6e67b2706fd263b8"
      ]
    ]
  },
  {
    "id": "5ac13c69086958ef",
    "type": "join",
    "z": "de43fb9fa12e01f7",
    "name": "",
    "mode": "custom",
    "build": "array",
    "property": "payload",
    "propertyType": "msg",
    "key": "topic",
    "joiner": "\\n",
    "joinerType": "str",
    "accumulate": false,
    "timeout": "",
    "count": "3",
    "reduceRight": false,
    "reduceExp": "",
    "reduceInit": "",
    "reduceInitType": "",
    "reduceFixup": "",
    "x": 700,
    "y": 101,
    "wires": [
      [
        "1694c420152ad442"
      ]
    ]
  },
  {
    "id": "b784f098ef1c16bf",
    "type": "inject",
    "z": "de43fb9fa12e01f7",
    "name": "写设备寄存器(每次写一个)",
    "props": [
      {
        "p": "payload"
      },
      {
        "p": "topic",
        "vt": "str"
      }
    ],
    "repeat": "",
    "crontab": "",
    "once": true,
    "onceDelay": 0.1,
    "topic": "",
    "payload": "",
    "payloadType": "date",
    "x": 330,
    "y": 100,
    "wires": [
      [
        "41d0f3a3c06f266c"
      ]
    ]
  },
  {
    "id": "18fa7f84a48de5c5",
    "type": "inject",
    "z": "de43fb9fa12e01f7",
    "name": "",
    "props": [
      {
        "p": "payload"
      },
      {
        "p": "topic",
        "vt": "str"
      }
    ],
    "repeat": "",
    "crontab": "",
    "once": false,
    "onceDelay": 0.1,
    "topic": "",
    "payload": "",
    "payloadType": "str",
    "x": 410,
    "y": 200,
    "wires": [
      [
        "6f3e223d63632890"
      ]
    ]
  },
  {
    "id": "6182c8cc4812806a",
    "type": "debug",
    "z": "de43fb9fa12e01f7",
    "name": "寄存器",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "payload",
    "targetType": "msg",
    "statusVal": "",
    "statusType": "auto",
    "x": 890,
    "y": 220,
    "wires": []
  },
  {
    "id": "6f3e223d63632890",
    "type": "modbus-server",
    "z": "de43fb9fa12e01f7",
    "name": "",
    "logEnabled": false,
    "hostname": "0.0.0.0",
    "serverPort": "502",
    "responseDelay": 100,
    "delayUnit": "ms",
    "coilsBufferSize": 10000,
    "holdingBufferSize": 10000,
    "inputBufferSize": 10000,
    "discreteBufferSize": 10000,
    "showErrors": false,
    "x": 569,
    "y": 198,
    "wires": [
      [
        "6182c8cc4812806a"
      ],
      [
        "6182c8cc4812806a"
      ],
      [
        "6182c8cc4812806a"
      ],
      [
        "6182c8cc4812806a"
      ],
      []
    ]
  },
  {
    "id": "ecf9bd4af996b17c",
    "type": "modbus-response",
    "z": "de43fb9fa12e01f7",
    "name": "",
    "registerShowMax": 20,
    "x": 1330,
    "y": 100,
    "wires": []
  },
  {
    "id": "3ec6c57aeedb4a1a",
    "type": "function",
    "z": "de43fb9fa12e01f7",
    "name": "转json",
    "func": "var rsp = {}\nrsp[\"hum\"]= msg.payload[0]\nrsp[\"temp\"] = msg.payload[1]\nmsg.payload = rsp\nreturn msg;",
    "outputs": 1,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 1010,
    "y": 640,
    "wires": [
      [
        "5074a82c47d68703",
        "d5bd28bacdf12440"
      ]
    ]
  },
  {
    "id": "5074a82c47d68703",
    "type": "debug",
    "z": "de43fb9fa12e01f7",
    "name": "json",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "payload",
    "targetType": "msg",
    "statusVal": "",
    "statusType": "auto",
    "x": 1110,
    "y": 220,
    "wires": []
  },
  {
    "id": "ad87da3c3ddc57cf",
    "type": "comment",
    "z": "de43fb9fa12e01f7",
    "name": "fc为功能码",
    "info": "01\t读线圈状态\t取得一组逻辑线圈的当前状态(ON/OFF)\n02\t读取输入状态\t取得一组开关输入的当前状态(ON/OFF)\n03\t读取保持寄存器\t在一个或多个保持寄存器中取得当前的二进制值\n04\t读取输入寄存器\t在一个或多个输入寄存器中取得当前的二进制值\n05\t强置单线圈\t强制一个逻辑线圈的通断状态\n06\t预置单寄存器\t把具体二进制值装入一个保持寄存器\n07\t读取异常状态\t取得8个内部线圈的通断状态,这8个线圈的地址由控制器决定\n08\t回送诊断检验\t把诊断检验报文送从机,以对通信处理进行评估\n09\t编程 (只用于484)\t使主机模拟编程器作用,修改PC从机逻辑\n10\t控询(只用于484)\t可使主机与一台正在执行长程序任务从机通信,探询该从机是够已完成其操作任务,仅在含有功能码9的报文发送后,本功能码才发送\n11\t读取事件计数\t可使主机发出单询问,并随即判定操作是否成功,尤其是该命令或其他应答产生通信错误时\n12\t读取通信事件记录\t可使主机检索每台从机的Modbus事务处理通信事件记录。如果某项事务处理完成,记录会给出相关错误。\n13\t编程(184/384/484/584)\t可使主机模拟编程器功能修改PC从机逻辑\n14\t探询(184/384/484/584)\t可使主机与正在执行任务的从机通信,定期控询该从机是否已完成其程序操作,仅在含有功能码13的报文发送后,本功能才得发送\n15\t强置多线圈\t强置一串连续逻辑线圈的通断\n16\t预置多寄存器\t把具体的二进制值装入一串连续的保持寄存器",
    "x": 200,
    "y": 680,
    "wires": []
  },
  {
    "id": "2978555ad9001ae2",
    "type": "comment",
    "z": "de43fb9fa12e01f7",
    "name": "unitid为设备ID",
    "info": "",
    "x": 210,
    "y": 720,
    "wires": []
  },
  {
    "id": "9da83077af267c0d",
    "type": "comment",
    "z": "de43fb9fa12e01f7",
    "name": "address为地址",
    "info": "",
    "x": 220,
    "y": 760,
    "wires": []
  },
  {
    "id": "21fe408f7090a6bb",
    "type": "comment",
    "z": "de43fb9fa12e01f7",
    "name": "quantity为数量",
    "info": "",
    "x": 220,
    "y": 800,
    "wires": []
  },
  {
    "id": "d5bd28bacdf12440",
    "type": "mqtt out",
    "z": "de43fb9fa12e01f7",
    "name": "通过mqtt发送到Thingspanel平台",
    "topic": "device/attributes",
    "qos": "",
    "retain": "",
    "respTopic": "",
    "contentType": "",
    "userProps": "",
    "correl": "",
    "expiry": "",
    "broker": "bf5a2e4e48b2bbdb",
    "x": 1310,
    "y": 640,
    "wires": []
  },
  {
    "id": "dc1ec22ef7dc9999",
    "type": "modbus-client",
    "z": "de43fb9fa12e01f7",
    "name": "",
    "clienttype": "tcp",
    "bufferCommands": true,
    "stateLogEnabled": false,
    "queueLogEnabled": false,
    "failureLogEnabled": false,
    "tcpHost": "localhost",
    "tcpPort": "502",
    "tcpType": "DEFAULT",
    "serialPort": "/dev/ttyUSB",
    "serialType": "RTU-BUFFERD",
    "serialBaudrate": "9600",
    "serialDatabits": "8",
    "serialStopbits": "1",
    "serialParity": "none",
    "serialConnectionDelay": "100",
    "serialAsciiResponseStartDelimiter": "",
    "unit_id": "1",
    "commandDelay": "1",
    "clientTimeout": "1000",
    "reconnectOnTimeout": false,
    "reconnectTimeout": "2000",
    "parallelUnitIdsAllowed": false
  },
  {
    "id": "bf5a2e4e48b2bbdb",
    "type": "mqtt-broker",
    "name": "thingspanel",
    "broker": "dev.thingspanel.cn",
    "port": "1883",
    "clientid": "",
    "autoConnect": true,
    "usetls": false,
    "protocolVersion": "4",
    "keepalive": "60",
    "cleansession": true,
    "birthTopic": "",
    "birthQos": "0",
    "birthPayload": "",
    "birthMsg": {},
    "closeTopic": "",
    "closeQos": "0",
    "closePayload": "",
    "closeMsg": {},
    "willTopic": "",
    "willQos": "0",
    "willPayload": "",
    "willMsg": {},
    "userProps": "",
    "sessionExpiry": ""
  }
]
插件信息
作者:
ThingsPanel
类别:
规则引擎
版本号:
v1.0
发布日期:
2023-07-28 14:29
Github
Gitee
微信交流群
QQ交流群
北京极益科技有限公司 版权所有 ICP:京ICP备15045763号-12