serial test
authorTomas Mudrunka <tomas@mudrunka.cz>
Tue, 15 Nov 2022 18:07:08 +0000 (19:07 +0100)
committerTomas Mudrunka <tomas@mudrunka.cz>
Tue, 15 Nov 2022 18:07:08 +0000 (19:07 +0100)
bash/serial_loopback_test.sh [new file with mode: 0644]

diff --git a/bash/serial_loopback_test.sh b/bash/serial_loopback_test.sh
new file mode 100644 (file)
index 0000000..6e24309
--- /dev/null
@@ -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<&-
This page took 0.127794 seconds and 4 git commands to generate.