From: Tomas Mudrunka Date: Tue, 15 Nov 2022 18:07:08 +0000 (+0100) Subject: serial test X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=55d43182ec793b929f94bc3cbe8a0c30d7243f75;p=mirrors%2FPrograms.git serial test --- diff --git a/bash/serial_loopback_test.sh b/bash/serial_loopback_test.sh new file mode 100644 index 0000000..6e24309 --- /dev/null +++ b/bash/serial_loopback_test.sh @@ -0,0 +1,35 @@ +#!/bin/bash +#(c) Tomas Mudrunka 2022 + +[ -z "$1" ] && { + echo "Usage: $0 /dev/ttyTX [/dev/ttyRX]" + exit 1 +} + +port_tx="${1:-/dev/ttyUSB0}" +port_rx="${2:-$port_tx}" + +testdata="${RANDOM}d82b2ae45432e7c80699852ab557b279c42180a379711aae85487bda0cc58602f65c0ab5af0d510d6ac1606c52f887f3332052f67c45212dbbf2730${RANDOM}" + +echo "Running loopback test on $port_tx -> $port_rx" + +stty -F "$port_tx" raw -echo +stty -F "$port_rx" raw -echo + +exec 5>"$port_tx" +exec 6<"$port_rx" + +errcnt=0 +while true; do + echo "$testdata" >&5 + unset line + read -rst 1 -u 6 line + #echo "LINE: $line" + [ "$line" != "$testdata" ] && { + ((errcnt=errcnt+1)) + echo -e "$(date +'%D %T')\t$errcnt\tError receiving data $port_tx -> $port_rx" + } +done + +exec 5>&- +exec 6<&-