# Modbus Flex Getter -\> Wrong value with Ferroamp!

**URL:** <https://discourse.nodered.org/t/modbus-flex-getter-wrong-value-with-ferroamp/60526>\
**Category:** Industrial\
**Created:** [30 March 2022 10:59 UTC](https://discourse.nodered.org/t/modbus-flex-getter-wrong-value-with-ferroamp/60526 "2022-03-30T10:59:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![olapola](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/olapola/32/5636_2.png) [@olapola](https://discourse.nodered.org/u/olapola)\
**Post date:** [30 March 2022 10:59 UTC](https://discourse.nodered.org/t/modbus-flex-getter-wrong-value-with-ferroamp/60526/1 "2022-03-30T10:59:46Z")

</div>

I'm using modbus for my solar inverter and I cant get the correct values from it. Ive tried searching the forum and I cant get it to work.

Its this bit that I cant understand:

> Data formats  
> The float data type can be accessed in two ways. The first two addresses use the single precision (32-  
> bit) floating point number as specified by IEEE 754 with the lower 16-bits at the lower address and  
> the higher 16-bits at the following address. The two consecutive addresses use two signed 16-bit  
> integers x, b such that the value represented is x \* 10^b. For example, consider the grid voltage L1  
> located at Modbus number 32032, address 2031. At address 2031 and 2032 the data will be {f15,f14,  
> ...,f0} and {f31,f30,...,f16} respectively, where fn is the n:th bit in the floating point representation. At  
> 2033 and 32034 the data will be {x15,x14,...,x0} and {b15,b14,...,b0} respectively.  
> The uint16\_t is a 16-bit unsigned integer and the int16\_t is a signed integer represented in the  
> binary two’s-complement form.

Im using **Modbus Flex Getter** with a function node:

Function node:

msg.payload = { 'fc': 4, 'unitid': 1, 'address': 2032, 'quantity': 4 };  
return msg;

And this is what I get to my **debug node** :

{"data":[62915,16967,4999,65534],"buffer":[245,195,66,71,19,135,255,254]}

The value should be ~230

[Ferroamp Modbus pdf](https://delafil.se/031642a274e572bf/Ferroamp_Modbus_TCP_Specification_RevB-1.pdf?download_token=2ab3b5518036b4c885c5ae9462dee30ff49707e2620014a315335b3129508c49)

Thankful for any help to point me in the right direction

 ![ferr](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/6/961da949da5a75eded46e5b5419e814d5b64778d.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:** [30 March 2022 19:12 UTC](https://discourse.nodered.org/t/modbus-flex-getter-wrong-value-with-ferroamp/60526/2 "2022-03-30T19:12:15Z")

</div>

No-one else has replied, so I will point you to node-red-contrib-buffer-parser, which I am sure will do what you want. Unfortunately I am not expert with that node, so you may still need input from someone else if you cannot work it out.

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [30 March 2022 22:35 UTC](https://discourse.nodered.org/t/modbus-flex-getter-wrong-value-with-ferroamp/60526/3 "2022-03-30T22:35:44Z")

</div>

Yep as Colin says - instead of trying to decode in a function node use Steves excellent buffer parser node and then put a debug on the ouput of that - but it is pretty self explanatory

Craig

---

<div class="post-metadata">

**Author:** ![MountainKing91](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mountainking91/32/59516_2.png) [@MountainKing91](https://discourse.nodered.org/u/MountainKing91)\
**Post date:** [4 April 2022 16:39 UTC](https://discourse.nodered.org/t/modbus-flex-getter-wrong-value-with-ferroamp/60526/4 "2022-04-04T16:39:27Z")

</div>

Hi,

what you are reading is the first 4 input registers starting from register 2032 (so Grid Voltage L1 and Grid Voltage L2); since you're reading 32 bit float data, these are stored over 2 16 bit registers each.  
The "data" output is returning the 4 registers values in 16 bit uint.  
The "buffer" output is returning the same, but expressed in bytes (each register is 2 bytes).

You can try with a function node wired to the "buffer" output of the modbus flex getter node, with this code (setup the function node in order to have 2 outputs):

```auto
let buffer = msg.payload.buffer;
var msg1 = {payload: buffer.readFloatLE(0)}; // first 32 bit float value (Grid Voltage L1 ?)
var msg2 = {payload: buffer.readFloatLE(4)}; // second 32 bit float value (Grid Voltage L2 ?)
return [msg1, msg2];

```

Some devices reverse the word order (big topic to explain here), so you might need to use

```auto
let buffer = msg.payload.buffer.swap16();

```

As others told you, you could go the easy way with the (awesome) buffer parser node.

---

<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 June 2022 16:40 UTC](https://discourse.nodered.org/t/modbus-flex-getter-wrong-value-with-ferroamp/60526/5 "2022-06-03T16:40:19Z")

</div>

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