Actually the length is number of registers, not the number of bits.
From the documentation
number of data items to read. Data items here refers to registers, coils or discrete inputs depending on the slave type. For example, if the goal is to read one item with valuetype=int32, one needs to read two registers (2 * 16bit = 32bit), thus length = 2. If three coils are of interest, one should specify length = 3
It sounds like reading works but writing does not like you expect??. I think you are suffering from this issue
This has been known issue for quite some time. See also docs for more information:
Note: The way Decimal commands are handled currently means that it is probably not useful to try to use Decimal commands with non-16bit valuetypes.
The reason for all of this is that there is no way to write individual bits to registers with modbus (protocol). You can only write whole 16 bit registers.
You can workaround this limitation by keeping the whole register in memory, and combining individual bit with that. It requires rules and additional items. The forum should have some guidance or tips regarding this.
I don’t understand the term “with the same items”? What do expect to achieve. I’m not sure what are “reels” in this case.
Btw, if in the first example you would like to write to modbus coils, but read the status from bits of holding registers – it is possible to configure with the binding.
All these details vary so much between slaves – it’s about conventions after all. Modbus protocol essentially just provides binary level access to data. This means it might be hard to understand what makes sense with your device, unless more context is given. For example, device name, link to manual, etc. If you can describe the interpretation of modbus input registers, holding registers, coils and discrete inputs with our device, it would help.
You have to find out (from the documentation) where to find the status of the relay.
Depending on the device it can be discrete input, input register or even holding register.
In general, no way to tell.
EDIT: for example: with my PLC, I can read the status of the output by reading the coil. I can also control the coil by setting (writing) it. With some devices reading the status is separated from command – this is your case.
EDIT2: I tried searching for “relay” or “reel” in the documentation but found nothing. Have a bit hard time deciphering this device myself.
The point is that Modpoll writes the COMPLETE 16-bit register to the slave. So does the OpenHAB binding.
It is not possible to write, say, bit 3 - and then later on write bit 4 while expecting bit 3 to remain the same. How could the slave know that you did not mean to turn bit 3 off?
If you can find a way that the device supports writing to relays as ‘modbus coils’ that would be easiest.
If you are stuck with bits-in-a-register, it is possible to write rules that keep a ‘shadow image’ of the register in OpenHAB, which allows other rules to change individual bits within it. When the shadow image changes, the binding writes the whole register to the slave.