modbus binding updated with serial support

1,292 views
Skip to first unread message

khome

unread,
Mar 6, 2013, 9:02:03 AM3/6/13
to ope...@googlegroups.com
Hi All
 
Attached please find updated modbus binding that has support for Modbus RTU protocol over COM port.
 
Please note that syntax of modbus configuration has changed: now u need to explicitly specify what type of slave you are using;
was:
modbus:slave.id=1
change to:
modbus:tcp.slave.id=1 or modbus:serial.slave.id=1
 
Also, IP and port or COM port and baud are now come from a single property - connection
was
modbus:slave.host=127.0.0.1
modbus:slave.port=502
change to
modbus:tcp.slave.connection=127.0.0.1:502
For TCP connection port is optional, defaults to 502, so modbus:tcp.slave.connection=127.0.0.1 will also work. For serial connection you need to put something like this modbus:serial.slave.connection=COM8:19200, baud is also optional, defaults to 9600
 
And you need org.openhab.io.transport.serial to run this binding
 
Thats it, comments welcome, happy openHABing :)
Thanks
Dmitry
org.openhab.binding.modbus-1.2.0-SNAPSHOT.jar

Kai Kreuzer

unread,
Mar 9, 2013, 5:04:10 PM3/9/13
to ope...@googlegroups.com
Hi Dmitry,

Does this mean that we should also update the Modbus binding in the official openHAB distribution? Are there any concrete changesets that we should pull for it?

Best regards,
Kai

--
You received this message because you are subscribed to the Google Groups "openhab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openhab+u...@googlegroups.com.
To post to this group, send email to ope...@googlegroups.com.
Visit this group at http://groups.google.com/group/openhab?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
<org.openhab.binding.modbus-1.2.0-SNAPSHOT.jar>

khome

unread,
Mar 9, 2013, 11:55:23 PM3/9/13
to ope...@googlegroups.com
I just need to polish the comments in the souce code - will send you changeset later next week

Thanks
Dmitry

воскресенье, 10 марта 2013 г., 2:04:10 UTC+4 пользователь Kai написал:

Dmitry Krasnov

unread,
Mar 10, 2013, 6:13:34 AM3/10/13
to ope...@googlegroups.com
I've updated the comments, changeset is 33a49aba77b8 (I am really awkward with this hg thing)




2013/3/10 Kai Kreuzer <k...@openhab.org>

--
You received this message because you are subscribed to a topic in the Google Groups "openhab" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openhab/NJMZR-ZJK-I/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to openhab+u...@googlegroups.com.

Thomas Eichstädt-Engelen

unread,
Mar 11, 2013, 7:19:21 PM3/11/13
to ope...@googlegroups.com
merged the changeset into default ...

Thomas Eichstädt-Engelen

unread,
Mar 11, 2013, 7:21:39 PM3/11/13
to ope...@googlegroups.com
but only changeset 33a49aba77b8 so far which does only contain javadoc changes, right?!


Begin forwarded message:

khome

unread,
Mar 12, 2013, 4:16:14 AM3/12/13
to ope...@googlegroups.com
Yes, apologies, looks like there are more changesets (as I said, I am really awkward with this source control system)

Thomas Eichstädt-Engelen

unread,
Mar 12, 2013, 4:34:13 PM3/12/13
to ope...@googlegroups.com
done


kbd...@gmail.com

unread,
Apr 16, 2013, 8:15:56 AM4/16/13
to ope...@googlegroups.com
Hi

I installed openhap 1.2.0 today.

Modbus section in my configuration file is:
############################### Modbus Binding ########################################
# sets refresh interval to Modbus polling service.
# Value in milliseconds (optional, defaults to 200)
modbus:poll=1000

# host (mandatory)
modbus:tcp.slave1.host=192.168.1.100:502

# The data type, can be "coil" "discrete" "holding" "input"
modbus:slave1.type=coil

# the TCP port (optional, defaults to '502')
#modbus:slave1.port=502


# The slave id (optional, defaults to '1')
#modbus:slave1.id=1
modbus:tcp.slave1.id=1


# The slave start address (optional, defaults to '0')
modbus:slave1.start=0

# The number of data item to read
# (optional, defaults to '0' - but set it to something meaningful)
modbus:slave1.length=0



my swithch modus binding is
Switch Light_GF_Corridor_Ceiling2     "My MB Switch"     (GF_Corridor, Lights) {modbus="slave1:0" }

a ss modbus on the prompt displays the following:
ss modbus
"Framework is launched."
id      State       Bundle
237     ACTIVE      org.openhab.binding.modbus_1.2.0.201304141051


Openhab is not polling the modbus client.

any ideas?

thanks

kbd...@gmail.com

unread,
Apr 16, 2013, 8:37:58 AM4/16/13
to ope...@googlegroups.com
Ok. some progress.

my openhab config file now looks like this:
modbus:poll=300
modbus:tcp.connection=192.168.1.100:502
modbus:tcp.slave1.id=1
modbus:tcp.slave1.start=0
modbus:tcp.slave1.length=1
modbus:tcp.slave1.type=coil


but still, openhab is not polling the client


any ideas?

thanks


On Wednesday, March 6, 2013 6:02:03 PM UTC+4, khome wrote:

Dmitry Krasnov

unread,
Apr 16, 2013, 10:50:38 AM4/16/13
to ope...@googlegroups.com
Can you try it with software client like ModbusSlave http://www.modbustools.com/modbus_slave.asp


2013/4/16 <kbd...@gmail.com>

--
You received this message because you are subscribed to a topic in the Google Groups "openhab" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openhab/NJMZR-ZJK-I/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to openhab+u...@googlegroups.com.

kbd...@gmail.com

unread,
Apr 17, 2013, 1:39:29 PM4/17/13
to ope...@googlegroups.com
Ok thanks. banged my head on it for 12 hours. now it works.

this is my config file

modbus:poll=1000
modbus:tcp.slave1.connection=192.168.0.252
modbus:tcp.slave1.length=3
modbus:tcp.slave1.type=coil

but every around 10-15 seconds i get the following error:

java.lang.IndexOutOfBoundsException
        at java.io.BufferedInputStream.read(Unknown Source)
        at java.io.DataInputStream.read(Unknown Source)
        at net.wimpi.modbus.io.ModbusTCPTransport.readResponse(ModbusTCPTransport.java:177)
        at net.wimpi.modbus.io.ModbusTCPTransaction.execute(ModbusTCPTransaction.java:193)
        at org.openhab.binding.modbus.internal.ModbusSlave.getModbusData(ModbusSlave.java:336)
        at org.openhab.binding.modbus.internal.ModbusSlave.update(ModbusSlave.java:278)
        at org.openhab.binding.modbus.internal.ModbusPoll.execute(ModbusPoll.java:92)
        at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:168)


any ideas?

many thanks in advance

Dmitry Krasnov

unread,
Apr 17, 2013, 4:02:33 PM4/17/13
to ope...@googlegroups.com
Could you please provide items definitions also. Did you try to simulate the same items with modbus slave tool?

Thanks
Dmitry


2013/4/17 <kbd...@gmail.com>

kbd...@gmail.com

unread,
Apr 18, 2013, 12:45:33 AM4/18/13
to ope...@googlegroups.com
Hi

these are the items definitions:
Switch Light_GF_Corridor_Ceiling2     "Heater 1"         (GF_Corridor, Lights) {modbus="slave1:0" }
Switch Light_GF_Corridor_Ceiling3     "Heater 2"         (GF_Corridor, Lights) {modbus="slave1:1" }

and yes, works well with the modbus tool, the number of errors is lower though.

regards

khome

unread,
Apr 19, 2013, 5:42:39 AM4/19/13
to ope...@googlegroups.com, kbd...@gmail.com
Sorry, still have no idea on what's wrong :( U said that testing with ModbusSlave ptoduces less errors - as I understand there are still errors? What kind? Maybe you hardware uses some non standard modbus impl?

четверг, 18 апреля 2013 г., 8:45:33 UTC+4 пользователь kbd...@gmail.com написал:

kbd...@gmail.com

unread,
Apr 19, 2013, 12:31:23 PM4/19/13
to ope...@googlegroups.com, kbd...@gmail.com
Sorry - I will need more time to be able to figure out what is happening. I will do more testing and i will keep u posted on the results.

meanwhile, it seem the modubustcp binding page is out of date:
http://code.google.com/p/openhab/wiki/ModbusTcpBinding

and needs updating to reflect the new binding syntax. whould it be possible to do so and maybe include some details on the INPUT and HOLDING registers data type?

thanks

kbd...@gmail.com

unread,
Apr 20, 2013, 4:59:35 PM4/20/13
to ope...@googlegroups.com, kbd...@gmail.com
very confused now.

I start openhab by double clicking on start.bat on windows.
openhab starts normally.
ss modbus says that the modbus module is loaded:
/////////////////
osgi> ss modbus

"Framework is launched."


id      State       Bundle
238     ACTIVE      org.openhab.binding.modbus_1.2.0.201304141051
/////////////////

however, it seems that sometimes, the modbus slaves are polled and some other times, the the modbus module is load but there is no polling or activity at all.

I have to restart openhab few times, until modbustcp module starts to work again.

am i missing something?


thanks



On Friday, April 19, 2013 1:42:39 PM UTC+4, khome wrote:

Thomas Eichstädt-Engelen

unread,
Apr 20, 2013, 5:22:28 PM4/20/13
to ope...@googlegroups.com
Hi,

would you mind creating an issue for the documentation issue?

Thanks,

Thomas E.-E.


You received this message because you are subscribed to the Google Groups "openhab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openhab+u...@googlegroups.com.

kbd...@gmail.com

unread,
Apr 22, 2013, 9:31:09 AM4/22/13
to ope...@googlegroups.com
Yes, sure I will.

now for the results of some testing over the past few days:
this is my modbus openhab configuration:
modbus:poll=1000
modbus:tcp.slave1.connection=192.168.1.100
modbus:tcp.slave1.id=1
modbus:tcp.slave1.length=3
modbus:tcp.slave1.type=coil

modbus:tcp.slave2.connection=192.168.1.100
modbus:tcp.slave2.id=1
modbus:tcp.slave2.start=6
modbus:tcp.slave2.length=1
modbus:tcp.slave2.type=input

I used ModScan32 from WInTech to poll the modbus controller board. the board can open only 10 sockets/connections simultaneously.
ModScan32 open two sockets to the controller board. uses the first one to poll the coil status and the second to poll the input register value.
in 1200 polls  get 1195 valid replies at a polling frequency of 1 poll per second. (which is very good)
the display on the controller shows that there are only 2 sockets open to the board.

now, with openhab:

1 - if I poll only the coils with openhab modbus configuration being:
modbus:poll=1000
modbus:tcp.slave1.connection=192.168.1.100
modbus:tcp.slave1.id=1
modbus:tcp.slave1.length=3
modbus:tcp.slave1.type=coil

I can see on the display of the controller that there are ONE opened sockets, which is the socket that openhab has initiated to read the coil values. - this is OK

2 - if I poll the coils AND the input registers with modbus configuration being:
modbus:poll=1000
modbus:tcp.slave1.connection=192.168.1.100
modbus:tcp.slave1.id=1
modbus:tcp.slave1.length=3
modbus:tcp.slave1.type=coil

modbus:tcp.slave2.connection=192.168.1.100
modbus:tcp.slave2.id=1
modbus:tcp.slave2.start=6
modbus:tcp.slave2.length=1
modbus:tcp.slave2.type=input

the display on the controller board shows the number of sockets opened growing up fast to 10. I then start to see high number of failure messages in the OSGI console.
It may be that that openhab opens two sockets initially: one to read the coils and one to poll the input register values. if on on the sockets times out, the openhab seems to open another socket (which is maybe why the number of sockets is growing fast up to 10).

Any ideas / hints / help is most appreciated.

Thanks

Dmitry Krasnov

unread,
Apr 22, 2013, 12:02:15 PM4/22/13
to ope...@googlegroups.com
Yes, you are right. Unfortunately current implementation does not support your configuration


2013/4/22 <kbd...@gmail.com>

kbd...@gmail.com

unread,
Apr 22, 2013, 12:31:16 PM4/22/13
to ope...@googlegroups.com
Thank you.

I may be able to reprogram the controllers to adjust to the behavior of the current implementation. I have few questions though:

1 - does openhab currently open on socket per configuration group?
2 - does the current implementation open the socket -> issue query ->get response -> close socket? and then reopens the socket again when the new polling round starts?
3 - what happens if a socket times out or gets an invalid response?
4 - what is the order of the polling round? is it the same order as that of the modbus items appearance/configuration in openhab.conf?
5 - is it asynchronous or synchronous in the sense that does it first query the coils, then after receiving an answer, it proceeds to query the INPUT registers?

Thanks

zmtgm...@gmail.com

unread,
Nov 25, 2014, 9:57:25 PM11/25/14
to ope...@googlegroups.com
Hi,
If I correctly read the code there is no bus concept? I mean I can only address one device per serial connection?

Reply all
Reply to author
Forward
0 new messages