Skip to content

Instantly share code, notes, and snippets.

@rudolfbyker
Created August 16, 2023 13:34
Show Gist options
  • Save rudolfbyker/7c054f32053d9faa086fafa7ca3355a9 to your computer and use it in GitHub Desktop.
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
#!/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