Modbus RTU over Ethernet encapsulation

Hello, I have a controller that uses modbus RTU Over Ethernet. This is usually Modbus RTU encapsulation in an Ethernet Packet. So, it does not work with Modbus TCP binding since it is Modbus with a special header.

I did a test with a proprietary M2M software, which has a binding called “Modbus IP” with a check box to select this option “Encapsulation”. My device works great with this.

Is it possible to use this option with OpenHab?

I did various tests to achieve this:

Using the option TCP with RTU I got this:

modbus:tcp.slave1.connection=192.168.0.121:502:rtu

2016-07-30 20:48:00.451 [DEBUG] [modbus.net.TCPMasterConnection] - connect()
2016-07-30 20:48:12.475 [INFO ] [.b.modbus.internal.ModbusSlave] - ModbusSlave error getting responce from slave
2016-07-30 20:48:17.490 [DEBUG] [modbus.net.TCPMasterConnection] - connect()
2016-07-30 20:48:29.518 [INFO ] [.b.modbus.internal.ModbusSlave] - ModbusSlave error getting responce from slave
2016-07-30 20:48:34.527 [DEBUG] [modbus.net.TCPMasterConnection] - connect()

And using normal TCP
modbus:tcp.slave1.connection=192.168.0.121:502

2016-07-30 20:53:00.667 [DEBUG] [modbus.net.TCPMasterConnection] - connect()
2016-07-30 20:53:12.696 [INFO ] [.b.modbus.internal.ModbusSlave] - ModbusSlave error getting responce from slave
2016-07-30 20:53:17.709 [DEBUG] [modbus.net.TCPMasterConnection] - connect()
2016-07-30 20:53:29.738 [INFO ] [.b.modbus.internal.ModbusSlave] - ModbusSlave error getting responce from slave
2016-07-30 20:53:34.749 [DEBUG] [modbus.net.TCPMasterConnection] - connect()

Thank you for your attention and sorry for my english.

I’m no expert on the TCP binding so I can’t really address whether it is possible with that or not.

If it turns out not to be possible, you can probably still make it work by coding the interaction outside of OH (e.g. using Python) and communicate with OH through the Exec binding, HTTP binding, REST API, and/or MQTT binding. Not the best solution but sometimes the way we have to do it.

Hi, thank you. By now I’m using a Virtual Serial Port Server, to emulate a COM Port and Binding it with OpenHab with Modbus Serial. It works fine.

Now I wonder how to connect it directly to OpenHab because it seems to be very a simple trick, but I’m not a Java Programmer, yet.

Unfortunately modbus RTU over tcp is not supported in the binding. For more information what modbus variants are supported, please consult the wiki article. There you can also find the syntax for tcp slave connection parameter (there is no way to specify modbus variant as RTU with tcp slaves)

I believe adding the support might not be trivial since the jamod library (java modbus library) that we use does not support it either. I would think that code need to be refactored such that the actual protocol (rtu/modbus tcp) is separated from the transport layer (tcp/serial). Perhaps you would like to try to do this? EDIT: found this fork of jamod that implements the feature on top of jamod. Perhaps the code could be integrated with our fork of jamod?

I find the virtual serial device really elegant way to handle this case. Perhaps you could document this to the wiki for other users?

Best
Sami

Thank you so much. I am starting with programming, I do some scripting, but I am a begginer. I will start to look the souce code and start to teach myself coding.
I would love to see this feature on Open Hab, since I have various devices using this protocol.

I am getting used with wiki, I edited Modbus Binding page, but it needs an adjust. The problem is when I try to edit it again I got 404 page. It seems they think I am a robot… I should stop digging the wiki…lol

Sounds excellent! Please feel free to ask if you need help with the implementation.

I looked a bit deeper with the fork and was not really happy with the quality. There were quite many unnecessary or unrelated changes but the basic structure is there. The developer went the pragmatic way: introducing new transport class etc and not trying to refactor the actual protocol away from the communication layer. It will be more duplicated / similar code but likely more straight forward code.

Hello, here is an article about Modbus over Ethernet that I’ve found

Have anybody tested this software?