Modbus Config

Hello I’m struggling with the modbus RTU communication on serial port.
The device provides a series of 16-bit words, each word reports the status and activation of the relays.


Bit 1 = 0 Relay 1 (OFF)
Bit 1 = 1 Relay 1 (ON)
Bit 2 = 0 Relay 2 (OFF)
Bit 2 = 1 Relay 2 (ON)
Bit 3 = 0 Relay 3 (OFF)
Bit 3 = 1 Relay 3 (ON)
Bit 4 = 0 Relay 4 (OFF)
Bit 4 = 1 Relay 5 (ON)

Items correctly report status but do not work on board relays.

Only the Item Switch U1_1 sometimes works …
I do not understand where I’m wrong

OH version 1.8.3

Modbus Binding 1.11.0

My file config:


My file Items:

Switch U1_1 “Uscita 1.1” (Uscite) {modbus=“O1:0”}
Switch U1_2 “Uscita 1.2” (Uscite) {modbus=“O1:1”}
Switch U1_3 “Uscita 1.3” (Uscite) {modbus=“O1:2”}
Switch U1_4 “Uscita 1.4” (Uscite) {modbus=“O1:3”}

With your items, I think you config wrong.
Your config file must be :


I think it’ll work. Good luck :slight_smile:


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.

Relevant section in docs

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 am sorry that the new versions of the 1.10.0 modbus binding have not been implemented to solve known problems.

I have tried this new working configuration.

But I still have a problem.
I ask, how can I read the status of the reels with the same items?

Sorry but I’m a beginner

My File config


My File Items

Switch U1_1 “Uscita 1.1” (Uscite) {modbus=“O1:0”}
Switch U1_2 “Uscita 1.2” (Uscite) {modbus=“O1:1”}
Switch U1_3 “Uscita 1.3” (Uscite) {modbus=“O1:2”}
Switch U1_4 “Uscita 1.4” (Uscite) {modbus=“O1:3”}

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.

Probably the translation creates problems in the concept.
I would like the Item

Switch U1_1 “Uscita 1.1” (Uscite) {modbus=“O1:0”}

report the status of the coils

because when I act on the reels by a button in the field, the status is not reported

I thank you for your time

If you want I can make the instructions of my modbus communication card available

DFTS_23MUK.pdf (143.1 KB)

your configuration above looks correct (with type=coil)

Having issues?

with this configuration I can act on the relays.

But I do not see the status of the relay if I act with the button in the field

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.

Commenting here on your comment in the other thread (accidental mixup threads?)

always with modpol I can activate the relays simply by pointing the word and modifying the single bit

I am not aware of such functionality of setting single bit inside a word (=16 bit register) with modpoll. As explained above

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.

Since modpoll just exposes pure Modbus protocol, it has no way of having that feature.

Can you share your modpoll command, I think there is mixup here still. It’s quite straightforward to convert modpoll read/write commands to relevant modbus binding configuration.

how can I show you the modpoll?

Whatever mean works for you? Screenshot, camera picture, but preferably in text format.

I understood you had working modpoll commands for reading and writing? If the modpoll commands are not working, we are in a dead end.

now I am attaching the test screens with Modbuspoll reading module DF 4 Relè

rd 257

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.

Haven’t we been around this before?

1 Like