Sharing common bus among different bindings

Hello,

Is there in OH technique that allows to share common bus among several bindings without conflicts? For example, several devices sits on common RS485 bus (for simplicity’s sake, all them have identical serial settings) and controls by different bindings. Now we want to change and poll state of devices. To do it without conflicts OH must have some locking or pooling mechanism for common bus. Is there such feature in OH?

I’m thinking of implementing bindings for few locally manufactured devices with RS485 bus. I wonder have I implement all device drivers in one binding or may spread them among several. In one consolidated binding I obviously can control access to common bus. But this is weak, isn’t scalable solution.

Without knowning what you are trying to do…, It doesn’t sounds as a good design to control the same hardware from different bindings.Seems to me like the idea of encapsulating is gone then. But I think that the Binding architecture in OpenHAB actually supports this in a very good manner.
Try to take a loook at some of the bindings, You could take a look at the DSC Alarm Binding, Squeezebox Binding, Z-Wave Binding just to mention a few. Especially the Z-Wave Binding also have to handle a huge amount of devices. Some examples of sharing the same infra structure could be found (eg. MQTT, MQTTitude), but it isn’t exactly using the same hardware, so it is kind of different.

I would suggest that you describe in some details that you have this idea to a new binding and also shortly describes the devices/hardware you will bind together. It will be a lot easier to come with some suggestions. Initially you should considder if the OpenHAB Bridge, Thing concept can help you, eventually create a POC for yourself and play around with it. It actually is quite easy to start a new binding (a matter of minutes).

I am speaking about different devices connected to common RS485 bus. In my case all this devices are from one manufacturer and it would relatively legal to implement one binding for all of them, like in Z-Wave binding. Now suppose I want to connect to common bus one more device from other manufacturer with its own binding implementation. How then bindings can coordinate access to the common bus?

If you should be able to put things in a shared Binding, you should also have something in common (e.g. communication protocol, configuration, etc). The more there is something in common, the more you can bundle it into the binding structure. If you the only thing you have in common is the protocol, I guess that you either have to implement a thing for each and every item you want to support. It is hard to decide in general terms what you can do and what not. I will suggest that you start off with defining a name to your binding. The name should describe what it supports. If already are facing troubles in finding that name, something might be wrong. Then you can do some POC on the devices that you support. I don’t believe that it is possible to create a all-in-one swiss army knife binding, but I might be wrong…

As far as my understanding of OpenHAB is, two binding can (by design) never know about each other. As I have understood things, encapsulation is the whole idea of creating bindings.
You should look into the io part of the OpenHAB architecture, but basically it doesn’t sound correct that different Bindings interface the same hardware. At least not if each binding needs exclusive access to a gateway device (in Z-Wave that would be the Controller). If you can define a shared low level component that handles the communication (Thread safe!) to the RS485 bus, it might be possible. You should definately look at the io part of the addon, and you will most definately need to do some POC and then in details describe what your idea is about.

I think you would be limited to putting them all in the same binding.

Have you looked at the Serial Binding?

No two bindings can access the same hardware at the same time. And by design, as @mr_eskildsen said, bindings have no direct way to communicate with each other. They data has to flow out to the OH abstractions (Things, Channels, Items, Event Bus) before coming back to another binding. So I’m not sure there would be a way to coordinate the effectively between multiple bindings that all depend upon one separate binding for accessing the device.

However, there are some exceptions which might prove helpful to look at. For example, to use the MQTT Action, you must also have the MQTT Binding installed. So they clearly have some sort of dependency upon each other. There might be a way to do something like this as well, though probably not between two separate bindings.

To share bus to multiple bindings is rather easy to implement. Basically you need to implement dedicated OSGi bundle which handle all communication to RS485 bus. Bundle could just pool the serial port access or fully implement used protocol to abstract the serial port communication to application layer protocol which another bindings could use. Then you use OSGi Declarative Service for dependency injection to use this bundle in several bindings.

Similar concept is already used in openHAB. See e.g. UPnP bundle (org.eclipse.smarthome.io.transport.upnp) which is used by many bindings to access devices which are using UPnP protocol.

Interesting point.
But it would then be neccesary to add the dedicated OSGI bundle to OpenHAB (eg. NOT the addons)?

The best approach, as is done with other bindings and as mentioned above is to split the low level access into an “io.transport” bundle. This should handle all the common protocol level stuff (eg at packet level) and should expose an API to allow bindings to connect to the bus, register for certain packets or devices and send data.

It’s still another “addon” bundle - it just exposes a different interface.

Thanks for clearifying