Logic Machine Forum
Modbus - Writing with bitmask - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Gateway (https://forum.logicmachine.net/forumdisplay.php?fid=10)
+--- Thread: Modbus - Writing with bitmask (/showthread.php?tid=1922)



Modbus - Writing with bitmask - iJAF - 19.02.2019

Hi,

I have several bits I have to write in some registers.

The reading is working fine with bitmask, but I don't want to read, just write.

When I write TRUE it always sets to "1" the first bit of the register, not the one selected in the bitmask.

Am I missing something ?


{"name":"Set Heat Mode"            ,"bus_datatype":"1","type":"register","datatype":"int16", "address":1057,    "value_bitmask":0x4,          "read_swap":"n",     "writable":1 },
{"name":"Set Cool Mode"            ,"bus_datatype":"1","type":"register","datatype":"int16", "address":1057,    "value_bitmask":0x8,          "read_swap":"n",     "writable":1 },
{"name":"Set Lock Mode"            ,"bus_datatype":"1","type":"register","datatype":"int16", "address":1057,    "value_bitmask":0x20,         "read_swap":"n",  "writable":1 },
{"name":"Set On Off"                  ,"bus_datatype":"1","type":"register","datatype":"int16", "address":1057,    "value_bitmask":0x80,         "read_swap":"n",  "writable":1 },
{"name":"Set Fan AUTO"             ,"bus_datatype":"1","type":"register","datatype":"int16", "address":1058,    "value_bitmask":0x80,         "read_swap":"n",     "writable":1 },
{"name":"Set Fan LOW"              ,"bus_datatype":"1","type":"register","datatype":"int16", "address":1058,    "value_bitmask":0x4,          "read_swap":"n",     "writable":1 },
{"name":"Set Fan MID"                ,"bus_datatype":"1","type":"register","datatype":"int16", "address":1058,    "value_bitmask":0x2,          "read_swap":"n",     "writable":1 },
{"name":"Set Fan HIGH"              ,"bus_datatype":"1","type":"register","datatype":"int16", "address":1058,    "value_bitmask":0x1,          "read_swap":"n",     "writable":1 },


Thank you


RE: Modbus - Writing with bitmask - admin - 19.02.2019

Bitmasks are supported only for reading. You will need an extra script for writing. You can create another profile field for direct register access without bitmasks, set it to write_only and disable writable for status entries that use bitmasks.

See this post for a short example: https://forum.logicmachine.net/showthread.php?tid=1777&pid=11025#pid11025


RE: Modbus - Writing with bitmask - iJAF - 19.02.2019

Thank you,

Are the bits only accessible by script :\ ?

I will have 35 units like this one :o !

So could I have the profiles to just read (+-30 in 30sec) and the scripts just to write at the same time ?

Thanks


RE: Modbus - Writing with bitmask - admin - 19.02.2019

You can use modbus proxy from scripts to write values to devices: https://forum.logicmachine.net/showthread.php?tid=387&pid=1953#pid1953

If you have a fixed addressing rules for multiple units you can use once script with tagged objects. By using source object address you can calculate output addresses etc.

From your profile example it looks like you need scripts anyway. Fan control bits should be exclusive, so only one mode can be set at a time.

On the other hand, if the register does not contain any usable configuration bits you can use register value as is and map it to custom values (off/low/medium/high/auto). This way you don't need additional script at least for fan control.


RE: Modbus - Writing with bitmask - iJAF - 19.02.2019

Thank you,

I will make a profile with the raw register without the bitmask, and then use a script to write the correct value based on the value of each bit, like you suggested in first post.

I'm am using Modbus TCP/IP, Is there any problem if the write happens at the same time of the reading other registers ?


RE: Modbus - Writing with bitmask - admin - 20.02.2019

The current implementation creates new connection for each write request. Each read cycle (all mapped registers) also creates new connection. We are working on implementing persistent mode where only one connection is used for reading and writing.