Serial binding: unplugging and plugging back in a USB serial device requires an openhab restart

I am using Centos 7 on a PC, running openhab 2.5M1 inside a docker container, managed using docker-compose.

I have an Arduino Mega running RFLink connected to the PC’s USB port. I’ve set the device name to be persistent in /etc/udev/rules.d/ so that the port is called USBrflink. Without this, the device name kept changing between ttyACM0 and ttyACM1. Anyhow, I have this in my docker-compose.yaml:

      EXTRA_JAVA_OPTS: "-Duser.timezone=Australia/Brisbane"
      - /dev/USBrflink

My items file:

String RFLink "RF Link Received Data" { serial="/dev/USBrflink@57600" } 

All is working great. However, if I unplugged the USB port and plug it back in, the whole binding stopped working. My Item stopped receiving any data and writing to it would cause an error.The only way I know to get it back working is to restart openhab.

Is there a way to handle the unplug / plug in without having to restart openhab? Perhaps handle the error gracefully and attempt to close/reopen the port?

Looking into the source code of the Serial Binding (openhab1-addons), it doesn’t seem that it would handle it in the binding.

Is there a way to handle the error / exception, and re-initialise the binding (so that it would reopen the port) somehow, from inside a rule or otherwise?

Update: I tried restarting the Serial binding, but that didn’t help:

stop org.openhab.binding.serial
start org.openhab.binding.serial

It seems that the problem is also related to the docker environment. I haven’t figured out how to solve this.

It is likely not related to the Docker environment, though that could be the case. I know with other bindings that use serial devices restarting the bundle is enough to fix the problem. Perhaps this is a limitation of the Oh 1.x serial binding. In OH 2.x bindings there is a common serial device service which probably handles giving up the lock when the binding restarts.

The problem is that when OH comes up it gets a lock on the file that represents the serial device. If you remove the plug the software has no way to know that device is gone so it doesn’t release the lock. When you plug the device back in, the old file location already exists and is locked so it creates a new one.

You are probably stuck restarting all of OH with the Serial 1.x binding at this point. Or, if you can code, building a 2.x version of the Serial Binding using the existing Serial bundle (Zwave and I think Zigbee use the bundle for an example) would be helpful.