# Modbus 16bit words to doubleword problems

**URL:** https://discourse.nodered.org/t/modbus-16bit-words-to-doubleword-problems/13453
**Category:** General
**Created:** [18 July 2019 16:13 UTC](https://discourse.nodered.org/t/modbus-16bit-words-to-doubleword-problems/13453 "2019-07-18T16:13:17Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![pautorras](https://avatars.discourse-cdn.com/v4/letter/p/c57346/32.png) [@pautorras](https://discourse.nodered.org/u/pautorras)
#### Post date: [18 July 2019 16:13 UTC](https://discourse.nodered.org/t/modbus-16bit-words-to-doubleword-problems/13453/1 "2019-07-18T16:13:17Z")

</div>

Hi Everyone,

I'm having problems converting modbus word registers (16 bits) to double (32 bits) format.  
Modbus RTU Buffered using node-red-contrib-modbus (4.1.3)

I've tryed to use this ([Buffer](https://nodejs.org/api/buffer.html)) in a function but it's not working fine:  
let VL1= msg.payload.buffer.readDoubleLE(0,2)  
Trying with BE and LE and it's not working fine. I think that with that buffer instruction it tooks 4 modbus words (4x 16bits)...

I don't know how to do it.  
Sometimes in other technologies like industrial PLC's i've used SHL (shift left), and other options to do that.  
In that ocasion I can't find the correct way to do it.

Can you help me please with it?

Thanks in advance

---

<div class="post-metadata">

### Author: ![pautorras](https://avatars.discourse-cdn.com/v4/letter/p/c57346/32.png) [@pautorras](https://discourse.nodered.org/u/pautorras)
#### Post date: [18 July 2019 16:23 UTC](https://discourse.nodered.org/t/modbus-16bit-words-to-doubleword-problems/13453/2 "2019-07-18T16:23:06Z")

</div>

Hello again,

Changing readDoubleBE with readInt32BE I'm getting some values right (not all).  
Working with it.

---

<div class="post-metadata">

### Author: ![pautorras](https://avatars.discourse-cdn.com/v4/letter/p/c57346/32.png) [@pautorras](https://discourse.nodered.org/u/pautorras)
#### Post date: [18 July 2019 17:21 UTC](https://discourse.nodered.org/t/modbus-16bit-words-to-doubleword-problems/13453/3 "2019-07-18T17:21:01Z")

</div>

Hello again,

No way  
😵

Someone knows how to do it?

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: [18 July 2019 17:38 UTC](https://discourse.nodered.org/t/modbus-16bit-words-to-doubleword-problems/13453/4 "2019-07-18T17:38:51Z")

</div>

Just do it yourself.

Use JavaScript [bitshift](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators) operators.

Try shifting 1 word 16 bits then add it to the next word.

---

<div class="post-metadata">

### Author: ![pautorras](https://avatars.discourse-cdn.com/v4/letter/p/c57346/32.png) [@pautorras](https://discourse.nodered.org/u/pautorras)
#### Post date: [18 July 2019 18:28 UTC](https://discourse.nodered.org/t/modbus-16bit-words-to-doubleword-problems/13453/5 "2019-07-18T18:28:19Z")

</div>

Thanks @Steve-Mcl,

It's working.  
I've tested this before, but mybe with some typing errors because the result was NaN.

Thanks!!
