Modbus binding direction control


I am trying to use single board computer with UART output with RS485 transceiver for modbus binding.

I am looking for controlling direction of RS485 IC using GPIO of single board computer.

Like other setting of specifying UART, baud rate etc. in openhab things configuration for modbus binding, is it possible to also include direction gpio so that it will be easy to integrate RS485 IC directly with single board computer?

Looking forward to having this feature in modbus binding.


Serial port settings are going through standard operating system APIs, hence there is no support for passing it through some sort of less common ways.
You may need custom kernel driver for you SBC which will take care of switching. I remember some devices having switchable serial ports, however each time I looked at these it was implemented through some custom C code. Although there is GPIO binding available through marketplace, it might not offer you enough of reliability as your modbus things will fail to get online unless GPIO binding is ready and gpio pins are set up properly through OH items/channels/rules.

An alternative way which I may suggest is getting this sort of settings applied early after operating system boot, i.e. before network, so when OH is booted serial port/tty is already there.

Edit - when I thought of it second time - you can implement your own custom serial port provider. Then, from binding point of view, everything remains the same, however you gain an interception point where you can adjust system/gpio calls to properly setup port.

Please refer to above diagram (Signal named F_RS485_DE). What I am looking for is possibility of specifying gpio which modbus thing can use as a direction control.

For example, the thing can be

Bridge modbus:serial:test [port="ttyS0", id=1, dir_control = "gpio1" ]

here dir_control is not yet part of modbus binding however, if it would have been there, it would have really simplified the hardware design.

If this is not possible, only way, I think i can take care of direction control is by adding external additional circuit for direction control.

Please let me know if there is any way to avoid external hardware and configure gpio in openhab as modbus serial thing with addtional setting for gpio for direction control.

I had a look on catalog card of sp3485, and RE/DE pins may have similar role to “rts/cts” in rs232. Looking at available options of serial endpoint in openhab-core I see there - flowControlIn and flowControlOut which are holders for above. If you would be able to map F_RS485_DE signal state in a way that operating system recognizes it as rts/cts toggles then it will work without changes to binding and serial transport.

Look closer at serial driver which is used to handle your uart device. It could be that with proper mapping in device tree it will just work.