Skip to content

Node-RED Flow Examples

How to write a variable using Modbus protocol?

Copy this flow and take it to Node-Red.

[
   {
      "id":"9fd6abc7.0062b8",
      "type":"tab",
      "label":"ACTIO 24 Modbus demo",
      "disabled":false,
      "info":""
   },
   {
      "id":"fc58a50d.f042d8",
      "type":"function",
      "z":"9fd6abc7.0062b8",
      "name":"FC 16 Addr 0x1000",
      "func":"msg.payload = {\n    'unitid': 97, \n    'fc': 16,  \n    'address': 0x1000,\n    'quantity': 1,\n    'value': msg.payload\n};\n\nreturn msg;",
      "outputs":1,
      "noerr":0,
      "x":570,
      "y":440,
      "wires":[
         [
            "414ff3f2.331fec"
         ]
      ]
   },
   {
      "id":"414ff3f2.331fec",
      "type":"modbus-flex-write",
      "z":"9fd6abc7.0062b8",
      "name":"",
      "showStatusActivities":true,
      "showErrors":true,
      "server":"45ad3dcb.aaaf14",
      "emptyMsgOnFail":true,
      "keepMsgProperties":false,
      "x":870,
      "y":340,
      "wires":[
         [
            "408695fb.e2b49c"
         ],
         [

         ]
      ]
   },
   {
      "id":"408695fb.e2b49c",
      "type":"debug",
      "z":"9fd6abc7.0062b8",
      "name":"",
      "active":true,
      "tosidebar":true,
      "console":false,
      "tostatus":false,
      "complete":"true",
      "targetType":"full",
      "x":1110,
      "y":340,
      "wires":[

      ]
   },
   {
      "id":"ce50219f.643ea",
      "type":"inject",
      "z":"9fd6abc7.0062b8",
      "name":"DO 1&2 disabled",
      "topic":"",
      "payload":"[0]",
      "payloadType":"json",
      "repeat":"2",
      "crontab":"",
      "once":true,
      "onceDelay":"0.1",
      "x":290,
      "y":420,
      "wires":[
         [
            "fc58a50d.f042d8"
         ]
      ]
   },
   {
      "id":"e81222cd.a191c",
      "type":"inject",
      "z":"9fd6abc7.0062b8",
      "name":"Pulse DO 1&2",
      "topic":"",
      "payload":"[3]",
      "payloadType":"json",
      "repeat":"2",
      "crontab":"",
      "once":true,
      "onceDelay":"2",
      "x":300,
      "y":480,
      "wires":[
         [
            "fc58a50d.f042d8"
         ]
      ]
   },
   {
      "id":"50f010ee.13113",
      "type":"inject",
      "z":"9fd6abc7.0062b8",
      "name":"9600 bps",
      "topic":"",
      "payload":"[1]",
      "payloadType":"json",
      "repeat":"",
      "crontab":"",
      "once":false,
      "onceDelay":0.1,
      "x":300,
      "y":180,
      "wires":[
         [
            "82c4ec74.ca3f7"
         ]
      ]
   },
   {
      "id":"82c4ec74.ca3f7",
      "type":"function",
      "z":"9fd6abc7.0062b8",
      "name":"FC 16 Addr 0x3001",
      "func":"msg.payload = {\n    'unitid': 97, \n    'fc': 16,  \n    'address': 0x3001,\n    'quantity': 1,\n    'value': msg.payload\n};\n\nreturn msg;",
      "outputs":1,
      "noerr":0,
      "x":560,
      "y":240,
      "wires":[
         [
            "414ff3f2.331fec"
         ]
      ]
   },
   {
      "id":"f478e24c.a476f",
      "type":"inject",
      "z":"9fd6abc7.0062b8",
      "name":"19200 bps",
      "topic":"",
      "payload":"[2]",
      "payloadType":"json",
      "repeat":"",
      "crontab":"",
      "once":false,
      "onceDelay":0.1,
      "x":300,
      "y":260,
      "wires":[
         [
            "82c4ec74.ca3f7"
         ]
      ]
   },
   {
      "id":"45ad3dcb.aaaf14",
      "type":"modbus-client",
      "z":"",
      "name":"",
      "clienttype":"serial",
      "bufferCommands":true,
      "stateLogEnabled":false,
      "queueLogEnabled":false,
      "tcpHost":"127.0.0.1",
      "tcpPort":"502",
      "tcpType":"DEFAULT",
      "serialPort":"/dev/ttymxc4",
      "serialType":"RTU-BUFFERD",
      "serialBaudrate":"19200",
      "serialDatabits":"8",
      "serialStopbits":"1",
      "serialParity":"none",
      "serialConnectionDelay":"100",
      "unit_id":"1",
      "commandDelay":"1",
      "clientTimeout":"1000",
      "reconnectOnTimeout":true,
      "reconnectTimeout":"2000",
      "parallelUnitIdsAllowed":true
   }
]