[SOLVED] Modbus binding (V2) serial problems

Using Rpi and a In-Circuit RS485 USB stick.
Nilan Comfort 300LR modbus device (ventilation system).
Openhab (apt-get) 2.4.0 M8.
Modbus version 2.4.M8 (provided in the M8 release)
Note for @ssalonen

Problem:
I believe there is a problem with the binding using serial connection and manual thing file. And I believe this could be related to the stopBits parameter.

I can get the communication to work when setting all up from PaperUI. Modbus serial slave, Regular Poll and Thing Data are all online, and I receive data just fine from the Nilan device.

Using the exact same settings in a thing file fails. Thing Data throws an error.

2018-12-16 22:54:04.722 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'nilan.things'

==> /var/log/openhab2/events.log <==

2018-12-16 22:54:04.853 [hingStatusInfoChangedEvent] - 'modbus:serial:myNilan' changed from UNINITIALIZED to INITIALIZING
2018-12-16 22:54:04.857 [hingStatusInfoChangedEvent] - 'modbus:serial:myNilan' changed from INITIALIZING to ONLINE
2018-12-16 22:54:04.872 [hingStatusInfoChangedEvent] - 'modbus:poller:myNilan:holdingRegisters' changed from UNINITIALIZED to INITIALIZING
2018-12-16 22:54:04.879 [hingStatusInfoChangedEvent] - 'modbus:poller:myNilan:holdingRegisters' changed from INITIALIZING to ONLINE
2018-12-16 22:54:04.886 [hingStatusInfoChangedEvent] - 'modbus:data:myNilan:holdingRegisters:hol201' changed from UNINITIALIZED to INITIALIZING

==> /var/log/openhab2/openhab.log <==

2018-12-16 22:54:04.880 [WARN ] [me.config.core.internal.ConfigMapper] - Could not set field value for field 'readStart': Can not set java.lang.String field org.openhab.binding.modbus.internal.config.ModbusDataConfiguration.readStart to java.math.BigDecimal
java.lang.IllegalArgumentException: Can not set java.lang.String field org.openhab.binding.modbus.internal.config.ModbusDataConfiguration.readStart to java.math.BigDecimal
	at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167) ~[?:?]
	at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171) ~[?:?]
	at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81) ~[?:?]
	at java.lang.reflect.Field.set(Field.java:764) ~[?:?]
	at org.apache.commons.lang.reflect.FieldUtils.writeField(FieldUtils.java:523) ~[38:org.apache.commons.lang:2.6.0]
	at org.apache.commons.lang.reflect.FieldUtils.writeField(FieldUtils.java:500) ~[38:org.apache.commons.lang:2.6.0]
	at org.apache.commons.lang.reflect.FieldUtils.writeField(FieldUtils.java:560) ~[38:org.apache.commons.lang:2.6.0]
	at org.eclipse.smarthome.config.core.internal.ConfigMapper.as(ConfigMapper.java:102) [97:org.eclipse.smarthome.config.core:0.10.0.oh240M8]
	at org.eclipse.smarthome.config.core.Configuration.as(Configuration.java:85) [97:org.eclipse.smarthome.config.core:0.10.0.oh240M8]
	at org.eclipse.smarthome.core.thing.binding.BaseThingHandler.getConfigAs(BaseThingHandler.java:274) [109:org.eclipse.smarthome.core.thing:0.10.0.oh240M8]
	at org.openhab.binding.modbus.internal.handler.ModbusDataThingHandler.initialize(ModbusDataThingHandler.java:327) [242:org.openhab.binding.modbus:2.4.0.M8]
	at sun.reflect.GeneratedMethodAccessor32.invoke(Unknown Source) ~[?:?]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
	at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:153) [102:org.eclipse.smarthome.core:0.10.0.oh240M8]
	at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:53) [102:org.eclipse.smarthome.core:0.10.0.oh240M8]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
	at java.lang.Thread.run(Thread.java:748) [?:?]

==> /var/log/openhab2/events.log <==

2018-12-16 22:54:04.903 [hingStatusInfoChangedEvent] - 'modbus:data:myNilan:holdingRegisters:hol201' changed from INITIALIZING to OFFLINE (CONFIGURATION_ERROR)
2018-12-16 22:54:04.910 [hingStatusInfoChangedEvent] - 'modbus:data:myNilan:holdingRegisters:hol202' changed from UNINITIALIZED to INITIALIZING

==> /var/log/openhab2/openhab.log <==

2018-12-16 22:54:04.908 [WARN ] [me.config.core.internal.ConfigMapper] - Could not set field value for field 'readStart': Can not set java.lang.String field org.openhab.binding.modbus.internal.config.ModbusDataConfiguration.readStart to java.math.BigDecimal
java.lang.IllegalArgumentException: Can not set java.lang.String field org.openhab.binding.modbus.internal.config.ModbusDataConfiguration.readStart to java.math.BigDecimal
	at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167) ~[?:?]
	at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171) ~[?:?]
	at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81) ~[?:?]
	at java.lang.reflect.Field.set(Field.java:764) ~[?:?]
	at org.apache.commons.lang.reflect.FieldUtils.writeField(FieldUtils.java:523) ~[38:org.apache.commons.lang:2.6.0]
	at org.apache.commons.lang.reflect.FieldUtils.writeField(FieldUtils.java:500) ~[38:org.apache.commons.lang:2.6.0]
	at org.apache.commons.lang.reflect.FieldUtils.writeField(FieldUtils.java:560) ~[38:org.apache.commons.lang:2.6.0]
	at org.eclipse.smarthome.config.core.internal.ConfigMapper.as(ConfigMapper.java:102) [97:org.eclipse.smarthome.config.core:0.10.0.oh240M8]
	at org.eclipse.smarthome.config.core.Configuration.as(Configuration.java:85) [97:org.eclipse.smarthome.config.core:0.10.0.oh240M8]
	at org.eclipse.smarthome.core.thing.binding.BaseThingHandler.getConfigAs(BaseThingHandler.java:274) [109:org.eclipse.smarthome.core.thing:0.10.0.oh240M8]
	at org.openhab.binding.modbus.internal.handler.ModbusDataThingHandler.initialize(ModbusDataThingHandler.java:327) [242:org.openhab.binding.modbus:2.4.0.M8]
	at sun.reflect.GeneratedMethodAccessor32.invoke(Unknown Source) ~[?:?]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
	at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:153) [102:org.eclipse.smarthome.core:0.10.0.oh240M8]
	at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:53) [102:org.eclipse.smarthome.core:0.10.0.oh240M8]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
	at java.lang.Thread.run(Thread.java:748) [?:?]

==> /var/log/openhab2/events.log <==

2018-12-16 22:54:04.924 [hingStatusInfoChangedEvent] - 'modbus:data:myNilan:holdingRegisters:hol202' changed from INITIALIZING to OFFLINE (CONFIGURATION_ERROR)
2018-12-16 22:54:04.933 [hingStatusInfoChangedEvent] - 'modbus:data:myNilan:holdingRegisters:hol203' changed from UNINITIALIZED to INITIALIZING

==> /var/log/openhab2/openhab.log <==

2018-12-16 22:54:04.935 [WARN ] [me.config.core.internal.ConfigMapper] - Could not set field value for field 'readStart': Can not set java.lang.String field org.openhab.binding.modbus.internal.config.ModbusDataConfiguration.readStart to java.math.BigDecimal
java.lang.IllegalArgumentException: Can not set java.lang.String field org.openhab.binding.modbus.internal.config.ModbusDataConfiguration.readStart to java.math.BigDecimal
	at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167) ~[?:?]
	at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171) ~[?:?]
	at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81) ~[?:?]
	at java.lang.reflect.Field.set(Field.java:764) ~[?:?]
	at org.apache.commons.lang.reflect.FieldUtils.writeField(FieldUtils.java:523) ~[38:org.apache.commons.lang:2.6.0]
	at org.apache.commons.lang.reflect.FieldUtils.writeField(FieldUtils.java:500) ~[38:org.apache.commons.lang:2.6.0]
	at org.apache.commons.lang.reflect.FieldUtils.writeField(FieldUtils.java:560) ~[38:org.apache.commons.lang:2.6.0]
	at org.eclipse.smarthome.config.core.internal.ConfigMapper.as(ConfigMapper.java:102) [97:org.eclipse.smarthome.config.core:0.10.0.oh240M8]
	at org.eclipse.smarthome.config.core.Configuration.as(Configuration.java:85) [97:org.eclipse.smarthome.config.core:0.10.0.oh240M8]
	at org.eclipse.smarthome.core.thing.binding.BaseThingHandler.getConfigAs(BaseThingHandler.java:274) [109:org.eclipse.smarthome.core.thing:0.10.0.oh240M8]
	at org.openhab.binding.modbus.internal.handler.ModbusDataThingHandler.initialize(ModbusDataThingHandler.java:327) [242:org.openhab.binding.modbus:2.4.0.M8]
	at sun.reflect.GeneratedMethodAccessor32.invoke(Unknown Source) ~[?:?]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]
	at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:153) [102:org.eclipse.smarthome.core:0.10.0.oh240M8]
	at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:53) [102:org.eclipse.smarthome.core:0.10.0.oh240M8]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]
	at java.lang.Thread.run(Thread.java:748) [?:?]

==> /var/log/openhab2/events.log <==

2018-12-16 22:54:04.949 [hingStatusInfoChangedEvent] - 'modbus:data:myNilan:holdingRegisters:hol203' changed from INITIALIZING to OFFLINE (CONFIGURATION_ERROR)

nilan.things file:

Bridge modbus:serial:myNilan [ port="/dev/ttyUSB0", id=30, baud=19200, stopBits="1", parity="even", dataBits=8, encoding="rtu" ] {
 
  Bridge poller holdingRegisters [ start=201, length=3, refresh=2000, type="holding" ] {
      Thing data hol201 [ readStart=201, readValueType="uint16" ]
      Thing data hol202 [ readStart=202, readValueType="uint16" ]
      Thing data hol203 [ readStart=203, readValueType="uint16" ]

   }
}

Setting up the things file and looking at the Modbus serial slave inside PaperUI, it seems to be lacking the stopBits parameter. I would expect it to show the exact same settings according to the thing file.

Setting up the Modbus serial slave from within PaperUI, it´s not missing the stopBits parameter.

This is the only differences I can find.
If the binding fails to read the stopBits from a .things file I would assume Thing Data will throw an error, as it cant readstart, ofcouse.

Edit your message header to give it a modbus tag

Maybe change stopBits="1" to stopBits=1

Done

Already tried that It throws a direct stopBits error.

Actually I believe I have tried all kinds of combinations. I used about 8 hours yesterday trying to get this working, (First I had huge problems getting symlinks to work for this specific USB stick, so the first few hours I struggled with communication issues). I gave up on symlinks for this USB stick, and finally got the RS485 stick to run on /dev/ttyUSB0, using PaperUI setup. This is how I know for sure, that it can communicate fine.

When I knew it finally worked from the PaperUI setup, I returned back to the manual .things file setup using the exact same settings… Then I ran into the above error.

Stopbit is not a number it’s a string and must be exact: stopBits="1.0".

The warnings in your log are about readStart. That is neither a number it’s also a String: so it must be readStart="201"

2 Likes

He’s right y’know. It pays to read the docs closely :slight_smile:

There is inconsistency between start addresses defined in Poller thing as integers, and in Data thing as strings. There is a reason - in Data you may wish to have a readStart of “234.5” to identify a bit in a register.

Not according to the doc´s… it should be “1” or “1.5” or “2”.
Doc´s could be wrong though. I never tried “1.0”

Ahh damit. I simply missed that part. I´m so sorry… :disappointed_relieved:

Will give it a try tonight. Hopefully this will be the reason, as it has driven me nuts all day yesterday, (including some damn symlinks issues I never got to work. But thats another story).

I did, several times. Probably my biggest mistake… I should have dumped the docs and stayed with your example in the first post in the other thread :slightly_smiling_face:

I didn’t look into the docs but in the source code :wink: The stopBits is a option list where the display values are 1, 1.5 and 2.0. But the actual values used are 1.0, 1.5 and 2.0. The display values is what PaperUI would show. (also the default is 1.0 so if you would leave out the stopBits is should also work)

I think this is an unfortunate event were it the values shown should reflect the actual value to be used. So maybe someone can update the docs/binding xml to reflect that.

Not at all - I got it wrong there, not appreciating this nasty pitfall.

Stop doing that… Thats not fair :smile:

So this is the reason why the stopBits parameter was empty in PaperUI? If I had used “1.0” in my nilan.things file, PaperUI would have showed “1” ?

It would have been nice to know the default settings, as I could have tried without stopBits.

Agree… And perhaps write the default settings as well.
I would probably prefere always to set the communication parameters and not leave out default settings… It kinda makes it more “understable”/makes more sense if someone sees the .things file.

Guess I just shut my mouth now and start getting this Nilan modbus thing to work :laughing:

Short update…
It seems like it´s working allright, (I just need to figure this weird modbus register addresses)… Just needed the “” in the readStart as hilbrand stated above. thank you very much, @hilbrand …

Good that this was sorted out.

Actually, docs do have the default values for parameters that are required. As far as I can tell stopbits is required (I.e. You cannot omit it in textual configuration), so you must provide something. However, it is true that when using Paper Ui, there are defaults for some parameters.

Having said all this, happy to review any doc updates if there’s something wrong.

I did raise a stopBits issue, as it obviously led to painful confusion.


Leave it to you to choose a fix :wink: (My vote for doc tweak i.e. recommend “1.0” to textual configs)

There’s a broader (XML?) issue really about allowing for multiple PaperUI actual settings values to lead to the same suggested values, e.g. “1” and “1.0” should both function. We had this before where both “uint32” and “int32” are acceptable text settings and only “int32” is actually needed in PaperUI. I’ve no idea how all that could work.

1 Like