Thanks, could you please make a Minimal config with single slave, matching the last query of modpoll? Please note that register 258 in modpoll corresponds to 257 in the binding.
Also please share all the logs with verbose level on pastebin.com. Now I see successful and error in the logs but do not know the general situation.
upload log to pastebin.com, a website for copy-pasting text. It’s really easy to use, just paste the log to the text box, click “Create new paste”, and copy the URL here.
You cannot simply change bits in a holding register. This is a limitation of Modbus. As far as the Openhab binding goes, it currently seems to try to write a single bit, but this results in bits above 0 being overwritten or blanked out.
I believe you will have to handle the whole register as a number item, and use rules to extract or set individual bits in that number at the Openhab end.
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
@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
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
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.
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.)
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