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

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

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

e.g....

//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...

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.

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

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

1 Like