I'm seeking a socat command combination to establish a connection over ssh to a remote virtual COM port so that the local virtual usb port behaves exactly the same as if the device would be attached to a local USB port. I already tried the following combinations:
socat -v PTY,link=$HOME/ttyVirt,raw,echo=0,b9600 EXEC:'ssh pi@192.168.5.30 socat - /dev/ttyACM0,pty,raw,echo=0'
socat -v PTY,link=$HOME/ttyVirt,raw,echo=0,icanon=1,b9600,crlf EXEC:'ssh pi@192.168.5.30 socat - /dev/ttyACM0,pty,raw,icanon=1,echo=0,crlf'
The initial connection to the device seems to work partly - I get some feedback with meaningful content. But than it stucks. My guess is, that socat adds some extra control commands to the data which goes over the socat relay.
Does anyone know how to establish such a 'clean' virtual COM port connection over ssh with socat?
As far as I know socat
does not add any control commands to the stream. My bet is there are some timing issues (network link adds a lot of latency that is not handled very well by many serial protocols).
It might be better to use some RFC 2217 based redirector (which supports more serial API calls -- e.g. change of speed etc.). I tested only ser2net which worked quite well.
If you insist on using socat
try to avoid using standard input/output as much as you can:
use stty
to pre-configure port (e.g. stty -F /dev/ttyACM0 9600 raw
) followed by GOPEN:/dev/ttyACM0
in socat
consider using SSH Port Forwarding instead of running socat
remotely via ssh. Then use standard TCP4-LISTEN
and TCP4
in socat
I had a working setup for this scenario but my commands are gone (I remember there was PTY
used for socat
to allocate virtual serial port).
EDIT>
Socat manual page offers this (adapted for your case):
socat PTY,link=$HOME/ttyVirt,rawer,wait-slave EXEC:"ssh pi@192.168.5.30 socat - /dev/ttyACM0,nonblock,rawer"
Good luck!