For my arduino projects I have started to wonder if it possible to use some kind of dialog program, like GtkDialog, and serial communication to make a frontend on a PC.
I want as few dependencies as possible.
From the top of my head I think I can make a dialog and send commands down the serial ( /dev/ttyUSB0 ) line. But I don't know how to read values back from the serial line asynchronously.
This code will do in a terminal
Code: Select all
#!/bin/bash
# interactive serial communication over usb port
# I tried it against arduino uno program
#
# SOURCE: https://unix.stackexchange.com/questions/22545/how-to-connect-to-a-serial-port-as-simple-as-using-ssh/311680#311680
#
if [[ $# -lt 1 ]]; then
echo "Usage:"
echo " femtocom <serial-port> [ <speed> [ <stty-options> ... ] ]"
echo " Example: $0 /dev/ttyS0 9600"
echo " Press Ctrl+Q to quit"
fi
# Exit when any command fails
set -e
# Save settings of current terminal to restore later
original_settings="$(stty -g)"
# Kill background process and restore terminal when this shell exits
trap 'set +e; kill "$bgPid"; stty "$original_settings"' EXIT
# Remove serial port from parameter list, so only stty settings remain
port="$1"; shift
# Set up serial port, append all remaining parameters from command line
stty -F "$port" raw -echo "$@"
# Set current terminal to pass through everything except Ctrl+Q
# * "quit undef susp undef" will disable Ctrl+\ and Ctrl+Z handling
# * "isig intr ^Q" will make Ctrl+Q send SIGINT to this script
# NOTE: This line did not work for me.
#stty raw -echo isig intr ^Q quit undef susp undef
# Let cat read the serial port to the screen in the background
# Capture PID of background process so it is possible to terminate it
cat "$port" & bgPid=$!
# Redirect all keyboard input to serial port
#cat >"$port"
while read cmd
do
echo "$cmd"
done > "$port"
Code: Select all
cat "$port" & bgPid=$!
This part
Code: Select all
while read cmd
do
echo "$cmd"
done > "$port"
Anyone know of examples or solutions I might use?