Linux/socat

From Omnia
Jump to navigation Jump to search

socat

Install:

sudo apt install socat

Server:

/usr/bin/socat tcp-listen:3333,reuseaddr,fork file:/dev/ttyUSB0,nonblock,waitlock=/var/run/tty0.lock,b115200,raw,echo=0
/usr/bin/socat tcp-listen:3333,reuseaddr,fork file:/dev/uart,nonblock,waitlock=/var/run/tty0.lock,b115200,raw,echo=0

Client:

killall -s 9 socat; sleep 5
while true ; do /usr/bin/socat pty,link=/dev/virtual0,waitslave tcp:socatserver.oeey.com:3333 ; sleep .001 ; done
while true ; do /usr/bin/socat pty,link=/dev/uart,waitslave tcp:socatserver.oeey.com:3333 ; sleep .001 ; done

For odd stop bit: [1]

socat -d -d -d -d  tcp-listen:4141,reuseaddr,fork  file:/dev/ttyUSB0,nonblock,cs8,b9600,cstopb=1,raw,echo=0
      cstopb=<bool>
             Sets two stop bits, rather than one.


socat-client.sh:

#!/bin/bash
set -e

if [ -z "$1" -o -z "$2" ]; then
    echo "Usage:    socat-client <server_url> <uart_path>"
    echo "Example:  socat-client target-pi /dev/ttyUSB0"
    exit 1
fi

trap "exit 1" SIGINT SIGKILL SIGTERM
while true; do
    killall -s 9 socat &> /dev/null || true
    echo "Starting socat client"
    /usr/bin/socat pty,link=$2,waitslave,unlink-close=0 tcp:$1:3333
done

ser2net

Alt - see Linux/ser2net

keywords