Socat (serial port forwarding) keeps crashing - how to stabilize?

You may want to have a look at what I use for my enOcean gateway. I pasted the code here:

After some tweaking it has now been running for months without any problems. Feel free to come back to me if you have any questions.