# Newbie: convert modbus float \[array\] register to float value

**URL:** <https://discourse.nodered.org/t/newbie-convert-modbus-float-array-register-to-float-value/20293>\
**Category:** General\
**Created:** [14 January 2020 04:14 UTC](https://discourse.nodered.org/t/newbie-convert-modbus-float-array-register-to-float-value/20293 "2020-01-14T04:14:29Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![mschmidt](https://avatars.discourse-cdn.com/v4/letter/m/97f17d/32.png) [@mschmidt](https://discourse.nodered.org/u/mschmidt)\
**Post date:** [28 February 2020 15:18 UTC](https://discourse.nodered.org/t/newbie-convert-modbus-float-array-register-to-float-value/20293/21 "2020-02-28T15:18:20Z")

</div>

Nope, I'm missing something...  
when its over 65353 I loose the base 65353 value.  
Dang it will try something else before I fill up this forum with my mistakes.

---

<div class="post-metadata">

**Author:** ![PPz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ppz/32/15429_2.png) [@PPz](https://discourse.nodered.org/u/PPz)\
**Post date:** [28 February 2020 15:48 UTC](https://discourse.nodered.org/t/newbie-convert-modbus-float-array-register-to-float-value/20293/22 "2020-02-28T15:48:10Z")

</div>

I have very little time for now but will reply to you asap.  
feel free to ask questions, we are on the very same boat 😉  
just play with node-red and google what you're looking for in the meantime.

---

<div class="post-metadata">

**Author:** ![PPz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ppz/32/15429_2.png) [@PPz](https://discourse.nodered.org/u/PPz)\
**Post date:** [28 February 2020 16:41 UTC](https://discourse.nodered.org/t/newbie-convert-modbus-float-array-register-to-float-value/20293/23 "2020-02-28T16:41:58Z")

</div>

Signed meaning that negative values are accepted  
Unsigned meaning that negative values are not accepted, just positive  
if you accept signed 16bit registers, your range is shifted (-32767 / 32767) vs unsigned (0-65535)

do you have a link to your hardware doc/pdf ?

---

<div class="post-metadata">

**Author:** ![mschmidt](https://avatars.discourse-cdn.com/v4/letter/m/97f17d/32.png) [@mschmidt](https://discourse.nodered.org/u/mschmidt)\
**Post date:** [28 February 2020 18:16 UTC](https://discourse.nodered.org/t/newbie-convert-modbus-float-array-register-to-float-value/20293/24 "2020-02-28T18:16:48Z")

</div>

Ok, so believe I've got it again on paper but not in node-red  
A= the 0 or 1 from first bit of register  
B = the value  
C = 65535  
so the math would be (A \* C) + B  
If it is below 65535 then the first bit would be 0 and the second bit would be the actual value  
so if the value on my device is 55 degrees  
then I would poll (0, 55000)  
so the math would be (0 \* 65535) + 55000 and would = 55000  
If my sensor was ready 66 degree then I would poll (1, 464)  
and the math would be (1 \* 65535) + 464 and would be 65999  
Heck maybe I make the fixed value 65536 for right on the money to 66000

that sound great, so I've been trying to repeat said math in a function block but with no success.  
So I've tried one Modus block with both resisters and two Modbus block with one register a piece and I don't know how to reference these in a function block.  
The value just get pushed through to the debug.  
I'm trying to reference (A, B) in my function block but that does not appear to under stand that A should be the first number and B should be the second number. I do see it comes out as an array and 0 is first

---

<div class="post-metadata">

**Author:** ![miraj](https://avatars.discourse-cdn.com/v4/letter/m/57b2e6/32.png) [@miraj](https://discourse.nodered.org/u/miraj)\
**Post date:** [20 July 2021 06:09 UTC](https://discourse.nodered.org/t/newbie-convert-modbus-float-array-register-to-float-value/20293/25 "2021-07-20T06:09:10Z")

</div>

Here is the right way to convert:

const buf = Buffer.allocUnsafe(4); // (4) is ok  
buf.writeUInt16BE(pay[0]); // high byte  
buf.writeUInt16BE(pay[1], 2); // low byte  
f = buf.readFloatBE(0);  
console.log(f)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [20 July 2021 06:21 UTC](https://discourse.nodered.org/t/newbie-convert-modbus-float-array-register-to-float-value/20293/26 "2021-07-20T06:21:01Z")

</div>



[Previous page](https://discourse.nodered.org/t/newbie-convert-modbus-float-array-register-to-float-value/20293.md?page=1)
