# Node-red Modbus RTU Data types Convert (unsigned Int to float)

**URL:** <https://discourse.nodered.org/t/node-red-modbus-rtu-data-types-convert-unsigned-int-to-float/65780>\
**Category:** General\
**Tags:** modbus\
**Created:** [29 July 2022 12:04 UTC](https://discourse.nodered.org/t/node-red-modbus-rtu-data-types-convert-unsigned-int-to-float/65780 "2022-07-29T12:04:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vikrimg](https://avatars.discourse-cdn.com/v4/letter/v/59ef9b/32.png) [@vikrimg](https://discourse.nodered.org/u/vikrimg)\
**Post date:** [29 July 2022 12:04 UTC](https://discourse.nodered.org/t/node-red-modbus-rtu-data-types-convert-unsigned-int-to-float/65780/1 "2022-07-29T12:04:08Z")

</div>

I got a project to read RS485 data using UART Modbus to Serial ([UART TTL to RS485 Two-way Converter | Elecrow](https://www.elecrow.com/uart-ttl-to-rs485-twoway-converter-p-1545.html)). before using node-red I use Arduino for this project and the project is succeed, I can read the data and converting it.

now I'm trying to using node-red and surprisingly I also got the data, but the problem is I can't convert the data in the program

this is the Raw value from the device (they say those data on FLOAT32 base on the datasheet)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/c/dcd9a8fff7bfb47d02043906963f6aa067824e6a.png)

the actual from the device is around 234,54.

and this is the Modbus register settings :  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/6/f64e6fbb60086c600360dade81c43fd09f74f10d.png)

here's the converting program from Arduino, which I got it from ([Modbus tips for Industruino | Industruino](https://industruino.com/blog/our-news-1/post/modbus-tips-for-industruino-26#blog_content))

```auto
float f_2uint_float(unsigned int uint1, unsigned int uint2) { // reconstruct the float from 2 unsigned integers

  union f_2uint {
    float f;
    uint16_t i[2];
  };

  union f_2uint f_number;
  f_number.i[0] = uint1;
  f_number.i[1] = uint2;

  return f_number.f;

}

```

Did anyone know how to convert the from the data from the device to the actual value?

---

<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:** [29 July 2022 12:47 UTC](https://discourse.nodered.org/t/node-red-modbus-rtu-data-types-convert-unsigned-int-to-float/65780/2 "2022-07-29T12:47:11Z")

</div>

[node-red-contrib-buffer-parser (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-buffer-parser) is designed for this very task.

---

<div class="post-metadata">

**Author:** ![vikrimg](https://avatars.discourse-cdn.com/v4/letter/v/59ef9b/32.png) [@vikrimg](https://discourse.nodered.org/u/vikrimg)\
**Post date:** [1 August 2022 04:58 UTC](https://discourse.nodered.org/t/node-red-modbus-rtu-data-types-convert-unsigned-int-to-float/65780/3 "2022-08-01T04:58:20Z")

</div>

ah yes, thank you. it work flawlessly

---

<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:** [15 August 2022 04:58 UTC](https://discourse.nodered.org/t/node-red-modbus-rtu-data-types-convert-unsigned-int-to-float/65780/4 "2022-08-15T04:58:56Z")

</div>

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