I'm using socat to route serial input over a network to allow me to control an Arduino device over a virtual COM port setup.
My command to start socat is:
socat /dev/serial0,b500000,raw,echo=0 TCP-LISTEN:9876,nodelay,fork&
This works the first time a device connects to the :9876 port perfectly fine. However, if the connection is dropped from the other end (which is using com2tcp on Windows), any further connections will send serial up the network to the RasPi hosting socat and out the serial device, but data will not be received in from /dev/serial0. I have to kill the original socat process, wait for the port to be released, and then re-run socat. Given the RasPi operates headless, this is an annoyance I'd rather avoid.
Is there any way to allow multiple, non-simultaneous connections to work in this manner? I'm assuming there's some sort of setting to put in after the echo=0
, but I can't figure out which one.
(Further notes: the 500000 baud rate is required, as this is the rate required for the software I'm using, called GIMX. The purpose of this setup is to allow me to connect to a game console with devices in another room, using the remote play functionality to play the game. I have this command set in /etc/rc.local
to start socat on boot, as the RasPi is also used as a media player using Volumio; this is simply running in the background.)
EDIT: I ended up abandoning the socat/com2tcp route, and implementing an RFC2247-compliant connection. This meant that I didn't have to worry about manually setting the baud rate as necessary, and seems to work in a more stable manner to boot. I based it on the information from https://robosavvy.com/forum/viewtopic.php?t=7578 which basically gives a full overview of setting it up. Although a couple of the links are dead, it has the information needed to get a connection going.
I believe the command I was looking for was "end-close", however I did not test this before having committed to the new setup.