Created
August 16, 2023 13:34
-
-
Save rudolfbyker/7c054f32053d9faa086fafa7ca3355a9 to your computer and use it in GitHub Desktop.
Wait for UART device, read it, and dump the received data to a text file and to the screen
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 | |
set -eu | |
DEVICE="$1" # e.g.: /dev/ttyUSB0 | |
BAUD_RATE="$2" # e.g.: 115200 | |
OUTPUT_FILE="$3" # e.g.: uart.txt | |
echo "Waiting for $DEVICE to become available ..." | |
while true | |
do | |
if [ -e "$DEVICE" ] | |
then | |
echo "Waiting for write permissions ..." | |
while [ ! -w "$DEVICE" ] | |
do | |
true | |
done | |
echo "Setting baud rate ..." | |
stty -F "$DEVICE" "$BAUD_RATE" | |
echo "Reading from $DEVICE to $OUTPUT_FILE" | |
tee "$OUTPUT_FILE" < "$DEVICE" | |
break | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment