Separation of Particular Bits in Holding Register

Holding or Input registers received from the controller can be separated into particular bits with the help of the following script:

IR.AddListener(IR.EVENT_TAG_CHANGE,IR.GetDevice("Modbus TCP"),function(name,value)
{
   switch (name) {
      case "Address 1": 
         var NewValue = parseInt(value.toString());
         var bit1 = (NewValue >> 0) & 0x1;
         var bit2 = (NewValue >> 1) & 0x1;
      break;
      case "Address 2":
         var NewValue = parseInt(value.toString());
         var bit2 = (NewValue >> 1) & 0x1;
         var bit6 = (NewValue >> 7) & 0x1;       
      break;
   }
});
Read more about Script API:
http://wiki2.iridiummobile.net/index.php/IRidium_Script_API (EN)

Ready samples:
separate bits - read.irpz
separate bits - rw.irpz

This article was helpful for 2 people. Is this article helpful for you?