Modbus Buffer parser, 32 bit

Hi there,
I would need your help please:
Reading 24 registers of a modbus TCP device:


And want to get the values. These are represented as followed:

How do I have setup the "puffer parser node", to get the values of the
current correctly? The output is an array of two words:

[
0,23758,
0,23817,
0,23873,
0,5000,
2,21400,
1,61664,
1,63560,
0,31044,
0,8869,
0,3992,
0,9726,
0,911
]

In Modbus Doctor, the setting of 32 bit word, unsigned and "swap words" is working well.

Flow:

[{"id":"a15ab1d7.fa063","type":"tab","label":"Stom","disabled":false,"info":""},{"id":"fa8953c2.b8e12","type":"function","z":"a15ab1d7.fa063","name":"Request","func":"msg.payload = { value: msg.payload,\n'fc': 3,\n'unitid': 255, \n'address': 50520 , \n'quantity': 24 }; \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":270,"y":38.00000762939453,"wires":[["4655e9ec.33a088"]]},{"id":"4655e9ec.33a088","type":"modbus-flex-getter","z":"a15ab1d7.fa063","name":"","showStatusActivities":false,"showErrors":false,"logIOActivities":false,"server":"d91e649d.344078","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"keepMsgProperties":false,"x":116.99998474121094,"y":94,"wires":[["209f93df.379b64","9dd4f771.e5aa88","66bdb7d5.b565d","b8e2078f.0334e8","cfb413bc.98f5d","e34f0bc5.81f57","6582ed29.ff8cbc","da1fff57.5f5da8"],[]]},{"id":"397df8c7.ed4e68","type":"inject","z":"a15ab1d7.fa063","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"10","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":111,"y":38.00000762939453,"wires":[["fa8953c2.b8e12"]]},{"id":"68912e04.eaf89","type":"debug","z":"a15ab1d7.fa063","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":334.25,"y":160.66666412353516,"wires":[]},{"id":"209f93df.379b64","type":"function","z":"a15ab1d7.fa063","name":"U Phase 1","func":"msg.payload=msg.payload[1]/100;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":124.16667175292969,"y":161.16665649414062,"wires":[["68912e04.eaf89"]]},{"id":"da1fff57.5f5da8","type":"debug","z":"a15ab1d7.fa063","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":530.25,"y":82.66666412353516,"wires":[]},{"id":"9dd4f771.e5aa88","type":"function","z":"a15ab1d7.fa063","name":"U Phase 2","func":"msg.payload=msg.payload[3]/100;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":126.16667175292969,"y":206.1666488647461,"wires":[["36b0b5e0.6083ea"]]},{"id":"66bdb7d5.b565d","type":"function","z":"a15ab1d7.fa063","name":"U Phase 3","func":"msg.payload=msg.payload[5]/100;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":126.16667175292969,"y":253.1666488647461,"wires":[["74bb973e.9dc068"]]},{"id":"36b0b5e0.6083ea","type":"debug","z":"a15ab1d7.fa063","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":335.16668701171875,"y":207.16665649414062,"wires":[]},{"id":"74bb973e.9dc068","type":"debug","z":"a15ab1d7.fa063","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":335.16668701171875,"y":253.16665649414062,"wires":[]},{"id":"b8e2078f.0334e8","type":"function","z":"a15ab1d7.fa063","name":"Frequenz","func":"msg.payload=msg.payload[7]/100;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":117.16667175292969,"y":301.1666488647461,"wires":[["534780a1.52c43"]]},{"id":"e34f0bc5.81f57","type":"function","z":"a15ab1d7.fa063","name":"I Phase 2","func":"msg.payload=msg.payload[11]/1000;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":116.16667175292969,"y":395.1666488647461,"wires":[["3a5ece87.e14efa"]]},{"id":"cfb413bc.98f5d","type":"function","z":"a15ab1d7.fa063","name":"I Phase 3","func":"msg.payload=msg.payload[13]/1000;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":118.16667175292969,"y":443.1666564941406,"wires":[["761129e7.60ee68"]]},{"id":"534780a1.52c43","type":"debug","z":"a15ab1d7.fa063","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":333.16668701171875,"y":302.1666564941406,"wires":[]},{"id":"12fab663.b2db52","type":"debug","z":"a15ab1d7.fa063","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":428.16668701171875,"y":346.1666564941406,"wires":[]},{"id":"3a5ece87.e14efa","type":"debug","z":"a15ab1d7.fa063","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":331.16668701171875,"y":396.1666564941406,"wires":[]},{"id":"761129e7.60ee68","type":"debug","z":"a15ab1d7.fa063","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":330.16668701171875,"y":442.1666564941406,"wires":[]},{"id":"6582ed29.ff8cbc","type":"buffer-parser","z":"a15ab1d7.fa063","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"uint32le","name":"item1","offset":9,"length":2,"offsetbit":0,"scale":1,"mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"value","resultTypeType":"output","multipleResult":false,"setTopic":true,"x":126.33335876464844,"y":347,"wires":[["12fab663.b2db52"]]},{"id":"d91e649d.344078","type":"modbus-client","name":"Diris A30 HV linkes Feld","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"192.168.130.161","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"255","commandDelay":"1","clientTimeout":"500","reconnectOnTimeout":false,"reconnectTimeout":"500","parallelUnitIdsAllowed":true}]

Thanks, Frank

  1. Set the debug coming out of modbus node to show complete message

  2. expand the debug output until you find a buffer object (something like msg.data.buffer)
    Copy the path to the buffer object using the button that appears under your mouse in the debug window item

  3. Set the buffer parser to use the path (that you copied in step 2) as its property...
    image

  4. Enter the data items on the buffer parser UI

  • As you request data from the modbus at address 50520...
    • use offset 0 for address 50520 (V1)
    • use offset 4 for address 50522 (V2)
    • use offset 8 for address 50524 (V3)
    • and so on

You will want the U32 values to be unsigned UINT32(BE) entries in the buffer parser
You will want the S32 values to be signed INT32(BE) entries in the buffer parser
(but I am guessing the endianess)

NOTE also, as V appears to be scalled by 100, you can set the scale item to 0.01 for a true value

1 Like

Thanks a lot for the great lesson and how to. This should be added to the buffer parser node doc.
This is a great base for starting to implement it on several modbus devices and it registers.

My application is now working fine and I can now log the data to my influxDB.

Here is the flow, if anyone can use it. The device where it's reading from is a Socomec
Diris A30 with Ethernet / Modbus TCP Option.

[{"id":"a15ab1d7.fa063","type":"tab","label":"Strom","disabled":false,"info":""},{"id":"fa8953c2.b8e12","type":"function","z":"a15ab1d7.fa063","name":"Request","func":"msg.payload = { value: msg.payload,\n'fc': 3,\n'unitid': 255, \n'address': 50520 , \n'quantity': 24 }; \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":270,"y":38.00000762939453,"wires":[["4655e9ec.33a088"]]},{"id":"4655e9ec.33a088","type":"modbus-flex-getter","z":"a15ab1d7.fa063","name":"","showStatusActivities":false,"showErrors":false,"logIOActivities":false,"server":"d91e649d.344078","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"keepMsgProperties":false,"x":134.99998474121094,"y":94.00000762939453,"wires":[[],["6582ed29.ff8cbc"]]},{"id":"397df8c7.ed4e68","type":"inject","z":"a15ab1d7.fa063","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":101,"y":38.00000762939453,"wires":[["fa8953c2.b8e12"]]},{"id":"6582ed29.ff8cbc","type":"buffer-parser","z":"a15ab1d7.fa063","name":"","data":"payload.buffer","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"uint32be","name":"L1U","offset":0,"length":1,"offsetbit":0,"scale":0.01,"mask":""},{"type":"uint32be","name":"L2U","offset":4,"length":1,"offsetbit":0,"scale":0.01,"mask":""},{"type":"uint32be","name":"L3U","offset":8,"length":1,"offsetbit":0,"scale":0.01,"mask":""},{"type":"uint32be","name":"freq","offset":12,"length":1,"offsetbit":0,"scale":0.01,"mask":""},{"type":"uint32be","name":"L1I","offset":16,"length":1,"offsetbit":0,"scale":0.001,"mask":""},{"type":"uint32be","name":"L2I","offset":20,"length":1,"offsetbit":0,"scale":0.001,"mask":""},{"type":"uint32be","name":"L3I","offset":24,"length":1,"offsetbit":0,"scale":0.001,"mask":""},{"type":"uint32be","name":"NI","offset":28,"length":1,"offsetbit":0,"scale":0.001,"mask":""},{"type":"int32be","name":"Pwirk","offset":32,"length":1,"offsetbit":0,"scale":10,"mask":""},{"type":"int32be","name":"Pblind","offset":36,"length":1,"offsetbit":0,"scale":10,"mask":""},{"type":"uint32be","name":"Pschein","offset":40,"length":1,"offsetbit":0,"scale":10,"mask":""},{"type":"int32be","name":"CosPhi","offset":44,"length":1,"offsetbit":0,"scale":0.001,"mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"output","multipleResult":false,"setTopic":true,"x":117.33335876464844,"y":154,"wires":[["9c5cad1a.58afa"]]},{"id":"6f1557fc.95083","type":"debug","z":"a15ab1d7.fa063","name":"U L1","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":382.25,"y":83.66666412353516,"wires":[]},{"id":"899a3e5b.c52768","type":"debug","z":"a15ab1d7.fa063","name":"U L2","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":381.16668701171875,"y":131.1666259765625,"wires":[]},{"id":"913fca98.cc7ff","type":"debug","z":"a15ab1d7.fa063","name":"U L3","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":384.16668701171875,"y":179.1666259765625,"wires":[]},{"id":"9c5cad1a.58afa","type":"split","z":"a15ab1d7.fa063","name":"split","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"topic","x":95.16667175292969,"y":303.1666564941406,"wires":[["6c7bbfa5.65c64"]]},{"id":"6c7bbfa5.65c64","type":"switch","z":"a15ab1d7.fa063","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"L1U","vt":"str"},{"t":"eq","v":"L2U","vt":"str"},{"t":"eq","v":"L3U","vt":"str"},{"t":"eq","v":"freq","vt":"str"},{"t":"eq","v":"L1I","vt":"str"},{"t":"eq","v":"L2I","vt":"str"},{"t":"eq","v":"L3I","vt":"str"},{"t":"eq","v":"NI","vt":"str"},{"t":"eq","v":"Pwirk","vt":"str"},{"t":"eq","v":"Pblind","vt":"str"},{"t":"eq","v":"Pschein","vt":"str"},{"t":"eq","v":"CosPhi","vt":"str"}],"checkall":"true","repair":false,"outputs":12,"x":216.1666717529297,"y":303.1666564941406,"wires":[["6f1557fc.95083"],["899a3e5b.c52768"],["913fca98.cc7ff"],["82b25fcc.a8ee1"],["c5814a0a.4b2368"],["8d344eb7.a562d8"],["ce2baa05.9eee2"],["fd10ceaf.d93808"],["37435e9c.554a5a"],["c4ce9b38.9199f"],["d9c605bf.16bd68"],["a9eb333d.ec6f4"]]},{"id":"82b25fcc.a8ee1","type":"debug","z":"a15ab1d7.fa063","name":"Hz","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":384.16668701171875,"y":227.16665649414062,"wires":[]},{"id":"c5814a0a.4b2368","type":"debug","z":"a15ab1d7.fa063","name":"I L1","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":382.16668701171875,"y":275.1666564941406,"wires":[]},{"id":"8d344eb7.a562d8","type":"debug","z":"a15ab1d7.fa063","name":"I L2","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":385.0833740234375,"y":324.6666259765625,"wires":[]},{"id":"ce2baa05.9eee2","type":"debug","z":"a15ab1d7.fa063","name":"I L3","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":382.0833740234375,"y":371.6666259765625,"wires":[]},{"id":"fd10ceaf.d93808","type":"debug","z":"a15ab1d7.fa063","name":"N L3","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":385.0833740234375,"y":421.6666564941406,"wires":[]},{"id":"37435e9c.554a5a","type":"debug","z":"a15ab1d7.fa063","name":"P Wirk","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":388.16668701171875,"y":473.1666564941406,"wires":[]},{"id":"c4ce9b38.9199f","type":"debug","z":"a15ab1d7.fa063","name":"P Blind","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":399.0833740234375,"y":521.6666259765625,"wires":[]},{"id":"d9c605bf.16bd68","type":"debug","z":"a15ab1d7.fa063","name":"P Schein","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":400.0833740234375,"y":572.6666259765625,"wires":[]},{"id":"a9eb333d.ec6f4","type":"debug","z":"a15ab1d7.fa063","name":"Cos Phi","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":400.0833740234375,"y":623.6666870117188,"wires":[]},{"id":"d91e649d.344078","type":"modbus-client","name":"Diris A30 HV linkes Feld","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"192.168.1.1","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":255,"commandDelay":1,"clientTimeout":500,"reconnectOnTimeout":false,"reconnectTimeout":500,"parallelUnitIdsAllowed":true}]

Thanks a gain, best regards,
Frank

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.