# Node-red-contrib-remote-io, digital output for joining bool to word

**URL:** <https://discourse.nodered.org/t/node-red-contrib-remote-io-digital-output-for-joining-bool-to-word/11798>\
**Category:** General\
**Created:** [3 June 2019 13:33 UTC](https://discourse.nodered.org/t/node-red-contrib-remote-io-digital-output-for-joining-bool-to-word/11798 "2019-06-03T13:33:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomrey](https://avatars.discourse-cdn.com/v4/letter/t/5f9b8f/32.png) [@tomrey](https://discourse.nodered.org/u/tomrey)\
**Post date:** [3 June 2019 13:33 UTC](https://discourse.nodered.org/t/node-red-contrib-remote-io-digital-output-for-joining-bool-to-word/11798/1 "2019-06-03T13:33:26Z")

</div>

Hi all,

# node-red-contrib-remote-io helps me splitting Modbus-words into bools through the digital input node.

Before sending bool back to my Wago PLC, I have to join bools back into word.  
Is there an opposite node available to node-red-contrib-remote-io digital-input-node?  
Can the same functionality perhaps be done with a different function/split/join?  
Regards

---

<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 June 2019 16:07 UTC](https://discourse.nodered.org/t/node-red-contrib-remote-io-digital-output-for-joining-bool-to-word/11798/2 "2019-06-03T16:07:20Z")

</div>

If you mean combining bits to make a WORD value - its just basic math functionality of the programming language.

e.g....

```auto
//Get bit
function getBit(number, bitPosition) {
  return (number & (1 << bitPosition)) === 0 ? 0 : 1;
}

//Set Bit
function setBit(number, bitPosition) {
  return number | (1 << bitPosition);
}

//Clear Bit
function clearBit(number, bitPosition) {
  const mask = ~(1 << bitPosition);
  return number & mask;
}

//Update Bit
function updateBit(number, bitPosition, bitValue) {
  const bitValueNormalized = bitValue ? 1 : 0;
  const clearMask = ~(1 << bitPosition);
  return (number & clearMask) | (bitValueNormalized << bitPosition);
}

```

You could use the code from these to update a WORD value and set / reset bits...

```auto
var plcValue = msg.payload;

//Set Bit 12
plcValue = plcValue | (1 << 12);

//reset Bit 3
const mask = ~(1 << 3);
plcValue = plcValue & mask;

msg.payload = plcValue; //(return this for next node to send it back to the PLC

```

Hope that helps.

---

<div class="post-metadata">

**Author:** ![tomrey](https://avatars.discourse-cdn.com/v4/letter/t/5f9b8f/32.png) [@tomrey](https://discourse.nodered.org/u/tomrey)\
**Post date:** [4 June 2019 06:23 UTC](https://discourse.nodered.org/t/node-red-contrib-remote-io-digital-output-for-joining-bool-to-word/11798/3 "2019-06-04T06:23:59Z")

</div>

Hi Steve,  
thanks a lot for your effort!  
Sorry that I'm not a programmer, just a user who wants to combine and configure nodes.  
Therefore I found the "node-red-contrib-remote-io, digital output", missing an corresponding "digital input".  
If I understand your code correctly in comparison with the "digital input" one would have to add a do-while loop according to the amount of bits (max. 16) to be packed.  
There is no itention of changing the bits, just packing into a word for modbus transportation.  
If I tried your code, what would I do with it? Copy paste into an existing node?  
Sorry for my ignorance. Regards Thomas

---

<div class="post-metadata">

**Author:** ![Ekristoffe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ekristoffe/32/11863_2.png) [@Ekristoffe](https://discourse.nodered.org/u/Ekristoffe)\
**Post date:** [10 September 2019 12:15 UTC](https://discourse.nodered.org/t/node-red-contrib-remote-io-digital-output-for-joining-bool-to-word/11798/4 "2019-09-10T12:15:23Z")

</div>

Hello all, I am currently updating the "node-red-contrib-remote-io" to include a Digital Output and also some improvement.
