# Modbus read two register into one opc tag

**URL:** <https://forum.inductiveautomation.com/t/modbus-read-two-register-into-one-opc-tag/41858>\
**Category:** Ignition\
**Created:** [December 30, 2020, 12:04pm UTC](https://forum.inductiveautomation.com/t/modbus-read-two-register-into-one-opc-tag/41858 "2020-12-30T12:04:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![SamuelsenLarsen](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/samuelsenlarsen/32/11901_2.png) [@SamuelsenLarsen](https://forum.inductiveautomation.com/u/SamuelsenLarsen)\
**Post date:** [December 30, 2020, 12:04pm UTC](https://forum.inductiveautomation.com/t/modbus-read-two-register-into-one-opc-tag/41858/1 "2020-12-30T12:04:33Z")

</div>

Hi,

I’m trying to read some values from a modbus TCP device. Some of the values are described as 2 word Long Interger in manual. When I set up OPC Ithem Path for the register that hold these values I use prefix HRI, but do not get the correct value. But if I read these two registers separately with the prefix HR, I get two numbers that will represent the correct value if I put them together.

HRI129 -\> 2163896  
HR129 -\> 33  
HR130 -\> 1208

The correct value is 331208.

I see how this arises with how the binary values are put together. But is there a way to get around this, or do I have to read all the register separately and then concat them together in a memory tag.

Regards Stian

---

<div class="post-metadata">

**Author:** ![brandon1](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@brandon1](https://forum.inductiveautomation.com/u/brandon1)\
**Post date:** [December 30, 2020, 3:18pm UTC](https://forum.inductiveautomation.com/t/modbus-read-two-register-into-one-opc-tag/41858/2 "2020-12-30T15:18:14Z")

</div>

> [@SamuelsenLarsen](#):
>
> I see how this arises with how the binary values are put together. But is there a way to get around this, or do I have to read all the register separately and then concat them together in a memory tag.

I believe you're going to have to put them together using an expression tag or a derived tag. The Modbus specification will always put them together using binary.

---

<div class="post-metadata">

**Author:** ![kcollins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kcollins/32/19646_2.png) [@kcollins](https://forum.inductiveautomation.com/u/kcollins)\
**Post date:** [December 30, 2020, 3:51pm UTC](https://forum.inductiveautomation.com/t/modbus-read-two-register-into-one-opc-tag/41858/3 "2020-12-30T15:51:16Z")

</div>

Agreed, what a strange device… You could create an expression tag (data type _Integer_) with `stringFormat("%d%d", {[~]HR129}, {[~]HR130})` and achieve what you’re looking for. It will concatenate the values together and the cast back to _Integer_ will handle converting it back to a number.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [December 30, 2020, 3:55pm UTC](https://forum.inductiveautomation.com/t/modbus-read-two-register-into-one-opc-tag/41858/4 "2020-12-30T15:55:01Z")

</div>

New crown for worst representation of a 32-bit value in Modbus.

---

<div class="post-metadata">

**Author:** ![kcollins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kcollins/32/19646_2.png) [@kcollins](https://forum.inductiveautomation.com/u/kcollins)\
**Post date:** [December 30, 2020, 4:01pm UTC](https://forum.inductiveautomation.com/t/modbus-read-two-register-into-one-opc-tag/41858/5 "2020-12-30T16:01:43Z")

</div>

If you are on 8.0+, you can also use a derived tag against the source `HRI129` that will help you guarantee an atomic read:

_Read Expression_  
`stringFormat("%d%d", ({source} >> 16), {source} & 0xFFFF)`  
_Write Expression_  
`{value}`

 ![2020-12-30 at 10.01 AM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/d/0d34d820d10229561e964bea48bcccc1ff061b77.png)

---

<div class="post-metadata">

**Author:** ![jay](https://avatars.discourse-cdn.com/v4/letter/j/ed8c4c/32.png) [@jay](https://forum.inductiveautomation.com/u/jay)\
**Post date:** [December 30, 2020, 5:38pm UTC](https://forum.inductiveautomation.com/t/modbus-read-two-register-into-one-opc-tag/41858/6 "2020-12-30T17:38:32Z")

</div>

It’s called “modulo 10000” and is common with old Modicon PLCs. A counter would automatically reset at 10000 and increment the next holding register.

For the strangest Modbus data format award, I submit the [16-bit floating point](https://en.wikipedia.org/wiki/Half-precision_floating-point_format) words used in some Morningstar solar charge controllers.

---

<div class="post-metadata">

**Author:** ![SamuelsenLarsen](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/samuelsenlarsen/32/11901_2.png) [@SamuelsenLarsen](https://forum.inductiveautomation.com/u/SamuelsenLarsen)\
**Post date:** [December 31, 2020, 2:52pm UTC](https://forum.inductiveautomation.com/t/modbus-read-two-register-into-one-opc-tag/41858/7 "2020-12-31T14:52:42Z")

</div>

Thank you all for the clarification and help in solving this.
