Modbus 32 Bit Float to an INT

Hi,

I have a power meter which I am pulling readings from via Modbus TCP. The data is in float & I need to put the 2 registers together then convert it to an integer.

just a note, I had to click the data in the array to toggle to Hex values.

Please can someone help on the best way around this.


please see screen shots.

Hello ..

you can use the node-red-contrib-buffer-parser node to do the conversion to float

Example Flow

[{"id":"2b690201c6ec9725","type":"function","z":"ee297f7b.69fda","name":"modbus fake data","func":"\nmsg.payload = Buffer.from([0x43, 0x74, 0x27, 0x0C])\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":470,"y":840,"wires":[["0dafbe21373e14c5","62ecced6b754b480"]]},{"id":"60815d2eb8942be6","type":"inject","z":"ee297f7b.69fda","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":280,"y":840,"wires":[["2b690201c6ec9725"]]},{"id":"dfb04119cbbb73a8","type":"debug","z":"ee297f7b.69fda","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":840,"wires":[]},{"id":"0dafbe21373e14c5","type":"buffer-parser","z":"ee297f7b.69fda","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"floatbe","name":"item1","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":710,"y":840,"wires":[["dfb04119cbbb73a8"]]},{"id":"62ecced6b754b480","type":"debug","z":"ee297f7b.69fda","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":600,"y":760,"wires":[]}]

If you wire the top modbus output to Buffer parser, the actual buffer will be in

image

So set that msg Property in the node's config instead of msg.payload

image

3 Likes

Thanks so much. What a great little tool. Much appreciated :+1:

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