# Function to add L and H registers in Modbus

**URL:** <https://discourse.nodered.org/t/function-to-add-l-and-h-registers-in-modbus/29221>\
**Category:** General\
**Created:** [30 June 2020 11:30 UTC](https://discourse.nodered.org/t/function-to-add-l-and-h-registers-in-modbus/29221 "2020-06-30T11:30:33Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![swanside](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/swanside/32/28781_2.png) [@swanside](https://discourse.nodered.org/u/swanside)\
**Post date:** [30 June 2020 11:30 UTC](https://discourse.nodered.org/t/function-to-add-l-and-h-registers-in-modbus/29221/1 "2020-06-30T11:30:33Z")

</div>

Hi all. I have seen various you tube videos on how it works but I cant figure out how to do it.  
I have my EP Solar controller and I want to get the values from Charging equipment input power L (3102) and Charging equipment input power H (3103) but I am getting confused on how to combine them together to give me one reading

 ![PV Aray](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/6/d6b474a2b5ba0aabe745d787b4a258e3095da968.jpeg)

Can anybody guide me to on how to get the correct values please?  
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:** [3 July 2020 21:55 UTC](https://discourse.nodered.org/t/function-to-add-l-and-h-registers-in-modbus/29221/2 "2020-07-03T21:55:37Z")

</div>

Did you solve this?

I suspect you need to read them in one read node (length 2) and you will get a single buffer containing both values. Then you can simply combine them to make the final number.

---

<div class="post-metadata">

**Author:** ![swanside](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/swanside/32/28781_2.png) [@swanside](https://discourse.nodered.org/u/swanside)\
**Post date:** [4 July 2020 08:02 UTC](https://discourse.nodered.org/t/function-to-add-l-and-h-registers-in-modbus/29221/3 "2020-07-04T08:02:01Z")

</div>

I did. I found a code somebody else made, and took that apart to see how it works. I use a function to read the registers into a modbus Flex Getter and send them to a switch and pull the individual values from there.  
Then put them into a join  
Cheers

---

<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 July 2020 08:08 UTC](https://discourse.nodered.org/t/function-to-add-l-and-h-registers-in-modbus/29221/4 "2020-07-04T08:08:50Z")

</div>

Glad you got it solved - though TBH, it sounds like you are polling 2 addresses in 2 separate reads then joining them together

You know you could (and should) read those 2 resisters in one go?

Reading multiple registers in one hit has the following benefits...

- halves the amount of comms (or speeds things up by 2x if you look at it from another perspective)
- ensures consistency (e.g. if the PLC/modbus device updates register 3103 as you are reading 3102, you end up with inconsistent data - trust me on this - it happens! ).

If you want an elegant way of handling this type of issue - let me know and I will help out.

---

<div class="post-metadata">

**Author:** ![swanside](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/swanside/32/28781_2.png) [@swanside](https://discourse.nodered.org/u/swanside)\
**Post date:** [4 July 2020 08:33 UTC](https://discourse.nodered.org/t/function-to-add-l-and-h-registers-in-modbus/29221/5 "2020-07-04T08:33:03Z")

</div>

Thanks Steve  
This is my testing I am looking at the battery power  
Thanks  
Paul  
[flows(3).json](https://discourse.nodered.org/uploads/short-url/mRJnfgpccy1ZMTeHPsewTnHtH3Z.json) (13.0 KB)

---

<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 July 2020 09:54 UTC](https://discourse.nodered.org/t/function-to-add-l-and-h-registers-in-modbus/29221/6 "2020-07-04T09:54:08Z")

</div>

Hi @swanside I think there is a fair bit of consolidation can be made & as a test i would like to try.

could you post the output of the flexgetter in a reply like this...

Add a debug set to "Show complete Message"...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/5/d58ebda3658587ea6899b8c9b9bb34ab617264ea.png)

copy the value...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/1/21d17a223c9b39e7031f47c2c45d96aa7022c0e5.png)

the paste copied msg in a reply  
`````  
`like this - between backticks`  
`````

Cheers.

---

<div class="post-metadata">

**Author:** ![swanside](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/swanside/32/28781_2.png) [@swanside](https://discourse.nodered.org/u/swanside)\
**Post date:** [4 July 2020 10:33 UTC](https://discourse.nodered.org/t/function-to-add-l-and-h-registers-in-modbus/29221/7 "2020-07-04T10:33:15Z")

</div>

Hi sorry for delay but got there eventualy. Thanks `{"topic":"livestats","messageId":"5f005a731cef5be24124c372","payload":[3127,277,8690,0,2750,316,8690,0,2750,8,0,0,0,0,0,0,2500,2173],"queueLengthByUnitId":{"unitId":1,"queueLength":0},"queueUnitId":1,"unitId":1,"modbusRequest":{"unitid":1,"fc":4,"address":12544,"quantity":18,"emptyMsgOnFail":false,"keepMsgProperties":false,"messageId":"5f005a731cef5be24124c372"},"responseBuffer":{"data":[3127,277,8690,0,2750,316,8690,0,2750,8,0,0,0,0,0,0,2500,2173],"buffer":[12,55,1,21,33,242,0,0,10,190,1,60,33,242,0,0,10,190,0,8,0,0,0,0,0,0,0,0,0,0,0,0,9,196,8,125]},"_msgid":"b74981da.d6c04"}`

---

<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:** [5 July 2020 18:32 UTC](https://discourse.nodered.org/t/function-to-add-l-and-h-registers-in-modbus/29221/8 "2020-07-05T18:32:48Z")

</div>

Hi so, I took a look at what you had and it seems you already get everything in one hit from the modbus node (good) - so no issue with consistency. Anyhow, I did say i would provide an elegant way of handling this - so, here you go.

Your flow...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/3/430936b87680a7530eeef895224262965862977a.png)

My adaption of your flow...

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/0/10681b0699f0938964061bc88da6d01f86040799.png)

The what and the why...

- no join nodes
- reduced duplication (only one scaling node)
- data is converted to individual objects with topic & payload in one node (the buffer-parser)
- more extensible / maintainable (i.e. if you add add another item, you dont need to modify the switch and add another change node for applying the topic & config is centralised)

NOTE: You will need [node-red-contrib-buffer-parser](https://flows.nodered.org/node/node-red-contrib-buffer-parser) node to use this

Hope its of some use.

---

<div class="post-metadata">

**Author:** ![swanside](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/swanside/32/28781_2.png) [@swanside](https://discourse.nodered.org/u/swanside)\
**Post date:** [7 July 2020 06:52 UTC](https://discourse.nodered.org/t/function-to-add-l-and-h-registers-in-modbus/29221/9 "2020-07-07T06:52:40Z")

</div>

Thanks Steve. WiIl take a closer look into that. Still have lots to learn and google

---

<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:** [5 September 2020 06:52 UTC](https://discourse.nodered.org/t/function-to-add-l-and-h-registers-in-modbus/29221/10 "2020-09-05T06:52:49Z")

</div>

Closed on 5 September 2020 06:52 UTC

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