Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
In linux redirect RS232 Serial Port traffic (in+out) to TCP port. Log all input + output to files. Its possible to connect with telnet to tcp-port. Short circuit COM pin 2+3 (in+out) to do loop-back test of connection without device attached, see http://www.ni.com/tutorial/3450/en/
#!/bin/bash
pid=$$
pgid=$(ps -o pgid= $$ | awk '{$1=$1;print}')
# netcat -l 7000 </dev/ttyUSB0 >/dev/ttyUSB0 &
cat /dev/ttyUSB0 | tee /var/log/lyngdorfSerial.ComToTcp.log | netcat -l 7000 | tee /var/log/lyngdorfSerial.TcpToCom.log > /dev/ttyUSB0 &
# Linux resets state when netcat closes com-port, so we need to se this after opening netcat
stty -F /dev/ttyUSB0 115200 cs8 -cstopb -parenb -echo
trap "logger 'killing lyngdorf prosess group $pgid'; echo 'kill -TERM -${pgid}'; kill -KILL -${pgid}; exit" INT TERM EXIT
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.