Help me Binding Modbus 1.9.0 holding

I’ve never had to do this, so no example.

Change Modbus data type
modbus:serial.O1.valuetype=uint16
This is to read/write the register bits combined as a single number

I think you then need an Item -
Number MyRegisterImage “Whole register value” {modbus:“O1:0”}
This will poll the register containing the bits of interest, and when sent a command within Openhab, write to the register.

Now you can define your individual bits as switch Items, for writing -
Switch MyBit00 “First bit”
Switch MyBit01 “Second bit”
etc.
Note that these ‘bits’ are NOT directly linked to Modbus.

Now we need a rule, which will respond to changes in the switches and send a new value on Modbus -

rule “action switch change”
when
Item MyBit00 received command or
Item MyBit01 received command
then
var Number skeleton = 0
if (MyBit00.state == ON) {
skeleton = skeleton + 1 // set bit 0
}
if (MyBit01.state == ON) {
skeleton = skeleton + 2 // set bit 1
}
MyRegisterImage.sendCommand(skeleton) // send the built-up number
end

This is all untried and probably needs work.
It has the limitation that it doesn’t read the initial state from Modbus and copy into the Switches. I think it would be possible to do that with a rule that triggered on update (not command) of ‘MyRegisterImage’, and then analysed the value by bits, and then updated (not command) the Switches. I think by using update in this way, it would prevent the whole thing getting into an update-command-update loop?

Edit - this looks useful for reading the bits if needed

1 Like

@omar1971 checked the logs. There are issues sometimes (as you also noticed) but every time it worked on the second try. The binding retries the read 3 times by default . So I would not be too worried.

Regarding write of bit values in holding registers, or actually writing anything <16bit, please note my comment in the beginning and other people’s workarounds

Best
Sami

Thanks for your help …
I pose a question …
but it should not be binding Modbus to solve problems?
I remember I used the equipment in question DFTS with a display screen of hakko model v606ec20 simply by configuring the Modbus communications and I had not encountered all these problems

Not sure I understand what are you trying to say?

There are two things here

  • writing individual bits to holding registers, via modbus. Currently not supported in the modbus binding without the workaround documented by @rossko57
  • logs having EOF ERRORs on read on first try, but successfull on second try. This is a low level issue with the serial library used by the openhab, or the an issue the way the serial library is used in modbus binding. So far (with binding > 1.9.0) I have seen this happening with windows.

For the interested, I discussed the implementation here as well.

Best,
Sami

Look at it this way; Modbus RTU FC16 only allows you to write whole 16-bit registers. That’s the way Modbus is, the binding cannot change that.

Modbus FC22 would allow you to set individual bits in a register, but it seems like Duemmegi did not implement that command in the DFTS module, so it doesn’t help you here.

So, any kind of host system wanting to update bits in a DFTS register has to do its own workaround somehow of re-writing a whole 16-bits to set the one(s) it wants.
This workaround is outside of the Modbus protocol, not everyone would want to use the same method.

There is more than one way to do this, and Openhab does provide you with the tools to do it.
Frustrating I know, but the limitation is in the DFTS module.
Modbus does provide a simple way to read and write individual bits in “contact/coil” format but Duemmegi chose not to use it in the DFTS. (The later DFCP4 product does use simple coil and contact form.)

Thank you for your help …
this weekend testing the rossko57 solution.
Thanks again.
I’ll keep you up-to-date

hello, I have tested the examples, it works correctly, but with a delay up to 4 seconds. can you optimize?
Also how can I view the icon lamp on or off
thank you

Make sure all your Modbus related cfg and Items are valid, in case it is getting bogged down by timeouts.

If you are happy there are no errors now, turn off debug

This post might help with lightbulb icons