This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Modbus - Writing with bitmask
#1
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
Reply
#2
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/showthrea...5#pid11025
Reply
#3
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
Reply
#4
You can use modbus proxy from scripts to write values to devices: https://forum.logicmachine.net/showthrea...53#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.
Reply
#5
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 ?
Reply
#6
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.
Reply


Forum Jump: