# Converting an uint32sw value (2 read modbus registers) to float

**URL:** <https://discourse.nodered.org/t/converting-an-uint32sw-value-2-read-modbus-registers-to-float/82595>\
**Category:** General\
**Tags:** modbus\
**Created:** [4 November 2023 07:17 UTC](https://discourse.nodered.org/t/converting-an-uint32sw-value-2-read-modbus-registers-to-float/82595 "2023-11-04T07:17:26Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![americanium](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@americanium](https://discourse.nodered.org/u/americanium)\
**Post date:** [4 November 2023 07:17 UTC](https://discourse.nodered.org/t/converting-an-uint32sw-value-2-read-modbus-registers-to-float/82595/1 "2023-11-04T07:17:26Z")

</div>

Hello!

I am getting information via Modbus from my pv inverter. The value "total\_power\_export" is stored in 2 registers as uint32sw.

How can i parse this information in a float value?

I tried a function with some codes from the internet, but none of them does work.

Thank you !

BR  
Alex

- List item

---

<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:** [4 November 2023 08:33 UTC](https://discourse.nodered.org/t/converting-an-uint32sw-value-2-read-modbus-registers-to-float/82595/2 "2023-11-04T08:33:35Z")

</div>

Many folk use [node-red-contrib-buffer-parser](https://flows.nodered.org/node/node-red-contrib-buffer-parser) for this type of task.

---

<div class="post-metadata">

**Author:** ![americanium](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@americanium](https://discourse.nodered.org/u/americanium)\
**Post date:** [4 November 2023 09:42 UTC](https://discourse.nodered.org/t/converting-an-uint32sw-value-2-read-modbus-registers-to-float/82595/3 "2023-11-04T09:42:09Z")

</div>

Hey,

i also tried that ... i couldn't get it work ...  
maybe an exampel for me ?  
Thanks!

---

<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:** [4 November 2023 09:55 UTC](https://discourse.nodered.org/t/converting-an-uint32sw-value-2-read-modbus-registers-to-float/82595/4 "2023-11-04T09:55:48Z")

</div>

If you provide sample data and the value you expect it to be, sure.

---

<div class="post-metadata">

**Author:** ![americanium](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@americanium](https://discourse.nodered.org/u/americanium)\
**Post date:** [4 November 2023 10:04 UTC](https://discourse.nodered.org/t/converting-an-uint32sw-value-2-read-modbus-registers-to-float/82595/5 "2023-11-04T10:04:34Z")

</div>

Sure:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/5/75e0566be9ab5b21daaa23d16d2a4dbd50bf6d09.png)

This is the output in a textbox:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/7/6739c3191bb29bb201b3257b639bb24d70051003.png)

Do you need more ?

---

<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:** [4 November 2023 10:13 UTC](https://discourse.nodered.org/t/converting-an-uint32sw-value-2-read-modbus-registers-to-float/82595/6 "2023-11-04T10:13:33Z")

</div>

> [@americanium](#):
>
> Do you need more

Yes...

> [@Steve-Mcl](#):
>
> and the value you expect it to be

I am not going to second guess the format of the data.

Also, does the devices manual give an example of this (e.g. [123,456] === 1.23455) and/or any details on how they compute the float from 32bit data?

---

<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:** [4 November 2023 10:23 UTC](https://discourse.nodered.org/t/converting-an-uint32sw-value-2-read-modbus-registers-to-float/82595/7 "2023-11-04T10:23:27Z")

</div>

Wait:

> [@americanium](#):
>
> This is the output in a textbox:  
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/7/6739c3191bb29bb201b3257b639bb24d70051003.png)

Is that how you want it to look? Or is that the value read from Modbus?

I need an example of modbus data (e.g. `[123,456]`) and how you expect it to be parsed (e.g. `1.23456`)

_as well as any info from the manual you can find_

---

<div class="post-metadata">

**Author:** ![americanium](https://avatars.discourse-cdn.com/v4/letter/a/c4cdca/32.png) [@americanium](https://discourse.nodered.org/u/americanium)\
**Post date:** [4 November 2023 11:13 UTC](https://discourse.nodered.org/t/converting-an-uint32sw-value-2-read-modbus-registers-to-float/82595/8 "2023-11-04T11:13:43Z")

</div>

> [@Steve-Mcl](#):
>
> Is that how you want it to look? Or is that the value read from Modbus?

That's the value how it is transmitted via modbus.  
The output after parsing should be like: 1200 (Watts) or 1533 (Watts) ...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/7/87b1062b58190a1f656cb5a0b1bb949c79d89d72.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [4 November 2023 11:44 UTC](https://discourse.nodered.org/t/converting-an-uint32sw-value-2-read-modbus-registers-to-float/82595/9 "2023-11-04T11:44:41Z")

</div>

> [@americanium](#):
>
> This is the output in a textbox:  
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/7/6739c3191bb29bb201b3257b639bb24d70051003.png)

I think Steve needs to know exactly what number that value represents (or show us a different value and exactly what it represents).

---

<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:** [4 November 2023 13:29 UTC](https://discourse.nodered.org/t/converting-an-uint32sw-value-2-read-modbus-registers-to-float/82595/10 "2023-11-04T13:29:24Z")

</div>

The closes I can get that to is:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/a/7ae4877d727e3020fdda1adae11e921dfa438591.png)

And that was only achieved by byte swapping the data (swap16) **and** using the `UINT32le` datatype type. Typically (but not always), Modbus data is packed in `be` (Big Endian)

I suspect 1 or more things

1. Your read request is off by 1 (i.e. it should be [5178,0])
2. The data is being reversed by your computer/server
3. You have processed the data (perhaps in a function) or the way the modbus node packed the data buffer into an integer array has manipulated it - and that is what you are showing us.

To be certain, you should read 7 registers from address 5010 and output the result to a debug node - then capture the FULL payload using the "Copy Value" button  
 ![Code_liI3XitWFU](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/7/07f441b6d9e5061af46db8a76a59ae9c7ab82e4d.gif)

Then tell me what they SHOULD be.

e.g.

| register | buffer | should be |
| --- | --- | --- |
| 5010 | [xx, yy] | 110.1 |
| 5011 | [xx, yy] | 110.6 |
| 5012 | [xx, yy] | 110.2 |
| 5013 | [xx, yy] | 12.5 |
| 5016 | [nn, oo, pp, qq] | 5000 |

  

Besides any how, you should be reading more than 1 item at a time and using the buffer-parser to convert everything in one go (helps with data consistency and reduced traffic) - see [this article](https://flowfuse.com/blog/2023/09/modernize-your-legacy-industrial-data-part2/) for details

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [3 January 2024 13:30 UTC](https://discourse.nodered.org/t/converting-an-uint32sw-value-2-read-modbus-registers-to-float/82595/11 "2024-01-03T13:30:01Z")

</div>

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