serial test
[mirrors/Programs.git] / bash / serial_loopback_test.sh
CommitLineData
55d43182
TM
1#!/bin/bash
2#(c) Tomas Mudrunka 2022
3
4[ -z "$1" ] && {
5 echo "Usage: $0 /dev/ttyTX [/dev/ttyRX]"
6 exit 1
7}
8
9port_tx="${1:-/dev/ttyUSB0}"
10port_rx="${2:-$port_tx}"
11
12testdata="${RANDOM}d82b2ae45432e7c80699852ab557b279c42180a379711aae85487bda0cc58602f65c0ab5af0d510d6ac1606c52f887f3332052f67c45212dbbf2730${RANDOM}"
13
14echo "Running loopback test on $port_tx -> $port_rx"
15
16stty -F "$port_tx" raw -echo
17stty -F "$port_rx" raw -echo
18
19exec 5>"$port_tx"
20exec 6<"$port_rx"
21
22errcnt=0
23while true; do
24 echo "$testdata" >&5
25 unset line
26 read -rst 1 -u 6 line
27 #echo "LINE: $line"
28 [ "$line" != "$testdata" ] && {
29 ((errcnt=errcnt+1))
30 echo -e "$(date +'%D %T')\t$errcnt\tError receiving data $port_tx -> $port_rx"
31 }
32done
33
34exec 5>&-
35exec 6<&-
This page took 0.13734 seconds and 4 git commands to generate.