# Scaled value while reading Modbus

**URL:** <https://discourse.nodered.org/t/scaled-value-while-reading-modbus/75871>\
**Category:** General\
**Created:** [28 February 2023 13:10 UTC](https://discourse.nodered.org/t/scaled-value-while-reading-modbus/75871 "2023-02-28T13:10:04Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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:** [1 March 2023 12:15 UTC](https://discourse.nodered.org/t/scaled-value-while-reading-modbus/75871/4 "2023-03-01T12:15:23Z")

</div>

> [@Manuel\_o](#):
>
> I have no idea how the number 9464 (that i can read from the modbus register) converts to 7500.
> 
> ![sasa](https://us1.discourse-cdn.com/flex026/uploads/nodered/optimized/3X/0/3/031224a4944ea3c4a51ca91d353b93128c202d11_2_690x23.png)

Some background:

- Modbus Registers are always 16 BIT
- That image shows you that 2 registers make up the HI and LO parts of the `DosingCapicty`
  - This leads me to think the data is either 32bit FLOAT or 32bit UINT

- Most manufacturers of Modbus devices store 32bit data in Big Endian - so I chose the Buffer-Parser type `UINT32BE` meaning take 8 bytes (aka 2x16 bit values aka 32bits) of data from the incoming data & convert them to a 32Bit Unsigned Integer using Big Endian format

When you convert the 2 16 bit values `[1, 9464]` into a 32Bit number (Big Endian) you get 75000

When you scale that by 0.1 (or more accurately divide it by 10) you get `7500`

#### Demo...

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

#### Buffer Parser

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

#### Demo Flow

```auto
[{"id":"37600721f03d9680","type":"inject","z":"08c327c2653de72a","name":"fake mobus data R300~R303","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[0, 0, 1, 9464]","payloadType":"json","x":1720,"y":100,"wires":[["d250bf3bda890004"]]},{"id":"d250bf3bda890004","type":"buffer-parser","z":"08c327c2653de72a","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"uint32be","name":"R300","offset":0,"length":1,"offsetbit":0,"scale":"/ 10.0","mask":""},{"type":"uint32be","name":"DosingCapacityMax","offset":4,"length":1,"offsetbit":0,"scale":"/ 10.0","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":1680,"y":160,"wires":[["4c6fa20bd13e4f9d"]]},{"id":"4c6fa20bd13e4f9d","type":"debug","z":"08c327c2653de72a","name":"debug 152","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1880,"y":160,"wires":[]}]

```

---

_[View the full topic](https://discourse.nodered.org/t/scaled-value-while-reading-modbus/75871)._
