Help me Binding Modbus 1.9.0 holding

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.

Best
Sami

Sorry … I do not understand what evidence do I need to run.
What is pastebin.com?
you can tell me I’m new
what files you need?

Hi

sorry for the unclear message

with minimal config I mean you have only one slave defined, corresponding to modpoll query, e.g.:

and only one item

Switch O1_1 “O1_1_” (c_o) { modbus=“O1:0” }

Then configure verbose logging according the instructions in the wiki.

Then

  1. clear existing logs
  2. start openhab with start_debug
  3. let it run for a while (e.g. 5 minutes)
  4. 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.

Best,
Sami

Hello,
I tried to paste the contents of Openhab.log files (eg 3 minutes) in Pastebin.com site but it is too big.
How do I proceed
Thank you

Hi

You can try to take the beginning of the log.

Pastebin.com should accept up to 0.5MB

Best
Sami

Hello,
this is the link
I hope it is correct

http://pastebin.com/ECxVX5rr

2° link

http://pastebin.com/Etp84wSu

3° link

http://pastebin.com/VJnnFeuM

4° link

http://pastebin.com/5nCJpdr3

configuration with a single word 257
and control of 4-bit switch.

Albeit very slowly, it works only bit 0 (controls the output and reports the status).
Bit 1-2-3 does not work

modbus:serial.O1.connection=COM2:19200:8:none:1:rtu
modbus:serial.O1.id=1
modbus:serial.O1.start=257
modbus:serial.O1.length=1
modbus:serial.O1.type=holding
modbus:serial.O1.valuetype=bit

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.

1 Like

can you help me.
I’m new with OpenHab and I do not know how to do.
Do you have any examples?

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