cserial() { local file="/dev/${1:-ttyUSB0}" # Use $1 if set; default to ttyUSB0 local baud_rate="${2:-9600}" # Use $2 if set; otherwise, default to 9600 # Does the device file exist if [ -e "$file" ]; then # Check for read and write permissions if [ -r "$file" ] && [ -w "$file" ]; then /usr/bin/cu -l "$file" -s ${baud_rate} else /usr/bin/echo "Device File $1 needs both read and write access!" fi else /usr/bin/echo "Device File $1 does not exist!" fi } tserial() { local file="/dev/${1:-ttyUSB0}" # Use $1 if set; default to ttyUSB0 local baud_rate="${2:-9600}" # Use $2 if set; otherwise, default to 9600 # Does the device file exist if [ -e "$file" ]; then # Check for read and write permissions if [ -r "$file" ] && [ -w "$file" ]; then /usr/bin/tip -$baud_rate $1 else /usr/bin/echo "Device File $1 needs both read and write access!" fi else /usr/bin/echo "Device File $1 does not exist!" fi } pserial() { local file="/dev/${1:-ttyUSB0}" # Use $1 if set; default to ttyUSB0 local baud_rate="${2:-9600}" # Use $2 if set; otherwise, default to 9600 # Does the device file exist if [ -e "$file" ]; then # Check for read and write permissions if [ -r "$file" ] && [ -w "$file" ]; then /usr/bin/putty "$file" -serial -sercfg ${baud_rate},8,n,1,N else /usr/bin/echo "Device File $1 needs both read and write access!" fi else /usr/bin/echo "Device File $1 does not exist!" fi } sserial() { local file="/dev/${1:-ttyUSB0}" # Use $1 if set; default to ttyUSB0 local baud_rate="${2:-9600}" # Use $2 if set; otherwise, default to 9600 # Does the device file exist if [ -e "$file" ]; then # Check for read and write permissions if [ -r "$file" ] && [ -w "$file" ]; then /usr/bin/screen "$file" $baud_rate else /usr/bin/echo "Device File $1 needs both read and write access!" fi else /usr/bin/echo "Device File $1 does not exist!" fi } mserial() { local file="/dev/${1:-ttyUSB0}" # Use $1 if set; default to ttyUSB0 local baud_rate="${2:-9600}" # Use $2 if set; otherwise, default to 9600 # Does the device file exist if [ -e "$file" ]; then # Check for read and write permissions if [ -r "$file" ] && [ -w "$file" ]; then /usr/bin/minicom -D "$file" -b $baud_rate else /usr/bin/echo "Device File $1 needs both read and write access!" fi else /usr/bin/echo "Device File $1 does not exist!" fi } serial() { if [ -z "$1" ]; then echo "Example: serial DEVICE_NAME BAUD_RATE" echo "Ex useage: serial ttyUSB0 115200" return 0 fi if id -nG "$USER" | grep -qw "dialout"; then echo -e "\n" else echo -e "To avoid running as Root, you should add yourself to the dialout group, so you can use serial...without being Root.\n" echo -e "You will need sudo access to do this, if you do not have SUDOers access, say no. \r\n Have an Admin do: usermod -a -G dialout $USER" echo -e "Do you want to add $USER to the dialout Group? \r\n" read -p "IF so, Type 'Yes' to continue: " response if [ "$response" = "Yes" ]; then echo -e "Adding $USER to dialout Group, enter sudo password" sudo usermod -a -G dialout $USER fi fi if [ -x /usr/bin/minicom ]; then mserial $@ elif [ -x /usr/bin/putty ]; then pserial $@ elif [ -x /usr/bin/screen ]; then sserial $@ elif [ -x /usr/bin/tip ]; then tserial $@ elif [ -x /usr/bin/cu ]; then cserial $@ else echo -e "Opps no minicom, putty, screen, cu, or tip programs installed!" fi }