Interesting SOCAT Commands

by

in

To be able to make a virtual null modem one can tun the following command:

socat -d -d pty,raw,echo=0 pty,raw,echo=0

This should output the follow:

2018/08/03 21:54:16 socat[32628] N PTY is /dev/pts/3
2018/08/03 21:54:16 socat[32628] N PTY is /dev/pts/4
2018/08/03 21:54:16 socat[32628] N starting data transfer loop with FDs [5,5] and [7,7]

Or similar. Obviously the dates will be different. To be able to open the location the right permission may be needed on execution of the terminal program of choice.

To make a serial port accessible over the network one can use the TCP listener with socat and use the following command:

sudo socat tcp-l:54321,reuseaddr,fork file:/dev/ttyUSB0,
nonblock,raw,echo=0,waitlock=/var/run/ttyUSB0.lock

The serial port may change depending on serial used and the port can also be selected as desired.

Finally anotehr interesting command with the socat is to make a virtual port connect to a network tcp server. For this the following command can be use:

socat pty,link=$HOME/dev/vmodem0,raw,echo=0,waitslave tcp:server.com:54321

Sources:

http://www.dest-unreach.org/socat/doc/socat-ttyovertcp.txt

https://rabinnankhwa.wordpress.com/2013/12/25/creating-a-null-modem-virtual-serial-port-pair-connection-with-socat/