# How to calculate negative modbus value?

**URL:** <https://discourse.nodered.org/t/how-to-calculate-negative-modbus-value/36283>\
**Category:** General\
**Created:** [21 November 2020 10:49 UTC](https://discourse.nodered.org/t/how-to-calculate-negative-modbus-value/36283 "2020-11-21T10:49:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![syma33](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/syma33/32/30665_2.png) [@syma33](https://discourse.nodered.org/u/syma33)\
**Post date:** [21 November 2020 10:49 UTC](https://discourse.nodered.org/t/how-to-calculate-negative-modbus-value/36283/1 "2020-11-21T10:49:59Z")

</div>

im stuck..

im reading modbus tcp values, when temperature goes -1 and below the graph seems to go bananas at night. Im trying to find out the right formula to calculate negative values passed from the modbus tcp.. i tried  
y=mx+c  
where x is analog value, y is values stored as max/min value in holding register(16bit)  
m=(Ymax-Ymin)/(Xmax-Xmin)

The sensor is a PT1000 and i base Xmax as Ymax.. in example.. PT1000tables at the internet shows me +50 at 1194ohm and -50 at 303ohm  
(50--50)/(1194-303) =\> 100/891=0,11 (m)

and... here im stuck, not sure what to do... maybe my sensor is bad or my node-red settings are bad ☹

 ![bild](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/f/8f05512dabba22f7bb3989da531113360816d970.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:** [21 November 2020 11:30 UTC](https://discourse.nodered.org/t/how-to-calculate-negative-modbus-value/36283/2 "2020-11-21T11:30:51Z")

</div>

Does the x value represent ohms or what?  
What x values are you getting and what values are X and Y max and min?  
What formula are you using at the moment and are the values correct for positive values?

---

<div class="post-metadata">

**Author:** ![samos](https://avatars.discourse-cdn.com/v4/letter/s/c89c15/32.png) [@samos](https://discourse.nodered.org/u/samos)\
**Post date:** [21 November 2020 11:59 UTC](https://discourse.nodered.org/t/how-to-calculate-negative-modbus-value/36283/3 "2020-11-21T11:59:05Z")

</div>

also check if you are using signed vs unsigned ints correctly - than can throw things around too...

---

<div class="post-metadata">

**Author:** ![syma33](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/syma33/32/30665_2.png) [@syma33](https://discourse.nodered.org/u/syma33)\
**Post date:** [21 November 2020 12:01 UTC](https://discourse.nodered.org/t/how-to-calculate-negative-modbus-value/36283/4 "2020-11-21T12:01:48Z")

</div>

> [@Colin](#):
>
> Does the x value represent ohms or what?  
> What x values are you getting and what values are X and Y max and min?  
> What formula are you using at the moment and are the values correct for positive values?

x = analogue signal but might not be ohm value, the FTX does not tell..  
for positive values, i just read it straight off the modbus 🙂

But i think i found my answer here... will try this solution soon.

> [@MODBUS 16bit SIGNED INTEGER](https://discourse.nodered.org/t/modbus-16bit-signed-integer/25362/4):
>

---

<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:** [21 November 2020 13:27 UTC](https://discourse.nodered.org/t/how-to-calculate-negative-modbus-value/36283/5 "2020-11-21T13:27:15Z")

</div>

If you are getting the right values without calculation for +ve but not for -ve then yes, you have a signed value which you need to convert to unsigned. It may be that you should be user the buffer-parser node for extracting the data, that will likely do everything you need in one go.

---

<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:** [21 November 2020 15:53 UTC](https://discourse.nodered.org/t/how-to-calculate-negative-modbus-value/36283/6 "2020-11-21T15:53:27Z")

</div>

Sorry, I didn't mean convert to unsigned, I meant that you should pick it up from the buffer, converting it a signed value as you do it, rather than an unsigned value.

---

<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:** [20 January 2021 15:53 UTC](https://discourse.nodered.org/t/how-to-calculate-negative-modbus-value/36283/7 "2021-01-20T15:53:42Z")

</div>

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