Created
November 25, 2018 10:23
-
-
Save arberg/cf8f2492ef8e2ec21910997adb3e19ea to your computer and use it in GitHub Desktop.
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# 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 | |
killtree() { | |
local _pid=$1 | |
local _sig=${2:--TERM} | |
kill -stop ${_pid} # needed to stop quickly forking parent from producing children between child killing and parent killing | |
for _child in $(ps -o pid --no-headers --ppid ${_pid}); do | |
killtree ${_child} ${_sig} | |
done | |
kill ${_sig} ${_pid} | |
} | |
background_pid=$! | |
trap "logger 'killing lyngdorf'; killtree $background_pid -KILL 2>/dev/null; exit" INT TERM EXIT | |
wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment