Convert ModBus Float32 to Dec

Hi everyone,

I have a ModBus register of 2 words in Float32. I can't convert it to decimal to import it into InfluxDB.

I can't config the Buffer Parser...

Help please :slight_smile:

  • Attach a debug to the output of the modbus node
    • set the debug to "show complete message"
  • copy the value using "copy value" button & paste it into a reply

image

Have a look to this link. Hope this helps.
https://www.unipi.technology/case_study/sending-temperatures-from-unipi-gate-to-a-thingsboard-cloud-392

Here :

[1,65472]

Except that the Getter ModBus does not deal with Float32 I think because I have two arrays... I don't understand anything anymore...

mod

Generally, I have these values coming up when I should have 50Hz stable.

zfgbrt

I cant help if you dont do what I ask.

That's what I did. There are two exits from the getter. Here they are:

First output :

[6554,65472]

Second output :

{"data":[6554,65472],"buffer":[25,154,255,192]}

Still no dice.

you are clicking the copy button while hovered on the payload

you need to click the button top most (the one by itself ) - like in the picture

Here you go :slight_smile:
Please forgive me, I am a novice....

First output :

{"topic":"b08c8b03.0ab7d8","messageId":"60a65c428f2c51a43672ee90","payload":[9700,65472],"queueLengthByUnitId":{"unitId":2,"queueLength":0},"queueUnitId":2,"unitId":2,"modbusRequest":{"value":1621515330131,"unitid":"2","fc":3,"address":"3110","quantity":"2","messageId":"60a65c428f2c51a43672ee90"},"responseBuffer":{"data":[9700,65472],"buffer":[37,228,255,192]},"_msgid":"587c6c81.d54b34"}

Second output :

{"topic":"b08c8b03.0ab7d8","messageId":"60a65c428f2c51a43672ee90","payload":{"data":[9700,65472],"buffer":[37,228,255,192]},"queueLengthByUnitId":{"unitId":2,"queueLength":0},"queueUnitId":2,"unitId":2,"modbusRequest":{"value":1621515330131,"unitid":"2","fc":3,"address":"3110","quantity":"2","messageId":"60a65c428f2c51a43672ee90"},"values":[9700,65472],"_msgid":"587c6c81.d54b34"}

So those values are weird. Do you have a manual - I suspect they are not straight forward float32 values.

also, what registers are you accessing in the modbus node (show picture)

Yes, it is an IEM 2150 counter : https://download.schneider-electric.com/files?p_enDocType=User+guide&p_File_Name=7EN02-0361-00.pdf&p_Doc_Ref=7EN02-0361

I would like to know the 3054 register

  • Set the modbus node to read from address 3000 & quantity to 77
    This will return 77 INT16 values (154 bytes)
    image

  • Add the below buffer parser (ctrl+i) to your flow and attach it to the top output
    image

    [{"id":"e61cc957.8e5ee8","type":"buffer-parser","z":"4b3f21a3.ba434","name":"","data":"responseBuffer.buffer","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatbe","name":"current","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"floatbe","name":"voltage","offset":56,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"floatbe","name":"activePower","offset":108,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"floatbe","name":"reactivePower","offset":136,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"floatbe","name":"apparentPower","offset":152,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"output","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":1350,"y":2540,"wires":[["cb923bba.971898"]]}]
    

What this will do is ...

  • modbus will return an array of 77 INT16 values (and a buffer of 154 bytes) for REGISTER 3000~3076 in an array (e.g. [val_of_3000,val_of_30001,etc,etc,etc])
  • It will also return these values as a Buffer in msg.responseBuffer.buffer - we will access these in the buffer parser
    • The buffer parser is set to grab a 32bit float (4 bytes) from byte offset 0 (aka Register 3000) and return it as msg.payload.current (see image below for ref)
    • The buffer parser is set to grab the next 32bits float (4 bytes) from byte offset 56 (aka Register 3028) and return it as msg.payload.voltage (see image below for ref)
    • etc etc

Why...

  • Because making 5 single requests is MUCH slower than grabbing all the data at once
  • Because grabbing individual values causes "inconsistent data"

//for reference

Ok, thanks for your reply !
But, the response of the Buffer Parser is :

RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 0. Received 56

Here the flow :

[{"id":"46d3f8ff.5cfc08","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"b08c8b03.0ab7d8","type":"modbus-getter","z":"46d3f8ff.5cfc08","name":"","showStatusActivities":true,"showErrors":false,"logIOActivities":false,"unitid":"2","dataType":"HoldingRegister","adr":"3000","quantity":"2","server":"111e1e7d.08f902","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"keepMsgProperties":false,"x":420,"y":300,"wires":[["e61cc957.8e5ee8"],[]]},{"id":"55d05965.f27718","type":"inject","z":"46d3f8ff.5cfc08","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":300,"wires":[["b08c8b03.0ab7d8"]]},{"id":"e61cc957.8e5ee8","type":"buffer-parser","z":"46d3f8ff.5cfc08","name":"","data":"responseBuffer.buffer","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatbe","name":"current","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"floatbe","name":"voltage","offset":56,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"floatbe","name":"activePower","offset":108,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"floatbe","name":"reactivePower","offset":136,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"floatbe","name":"apparentPower","offset":152,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"value","resultTypeType":"output","multipleResult":true,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":670,"y":300,"wires":[[]]},{"id":"111e1e7d.08f902","type":"modbus-client","name":"","clienttype":"serial","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"127.0.0.1","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB0","serialType":"RTU","serialBaudrate":"19200","serialDatabits":"8","serialStopbits":"1","serialParity":"even","serialConnectionDelay":"100","unit_id":10,"commandDelay":1,"clientTimeout":1000,"reconnectOnTimeout":true,"reconnectTimeout":2000,"parallelUnitIdsAllowed":true}]

You are requesting 2 registers from modbus...
image
... 2 registers is == 4 bytes


The buffer parser is set to parse multiple values (current, voltage, etc) from ...

  • offset 0 (reg 3000)
  • offset 56 (reg 3028)
  • offset 108 (reg 3054)
  • offset 136 (reg 3068)
  • offset 152 (reg 3076)

    ... so needs MORE than 4 bytes

If you want this to work, you need to grab all the registers in one go as described...

Hi Steve,

I found the solution by chance. I turned the buffer parser around until I found my expected value.
I also called Schneider Electric who pointed out an error in the calculation note: all values in Float32 are expressed in Kilo.
Moreover, the MSB must be switched to the left for reading.
Here is the flow:

[{"id":"bc264764.dff808","type":"buffer-parser","z":"f92e921.524f77","name":"Float 32 to Dec","data":"responseBuffer.buffer","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatbe","name":"Puissance (Wh)","offset":0,"length":1,"offsetbit":0,"scale":"1000","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"value","resultTypeType":"output","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":380,"y":120,"wires":[["f704a034.13002"]]}]

So simple and so complicated at the same time !

Thanks for your involvement and I hope others can be helped!

1 Like

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