Created
July 3, 2023 04:15
-
-
Save anthonylavado/6e959b3300c046a1d21a0445fc7834bb to your computer and use it in GitHub Desktop.
Controlling a MX42HS via Bash
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 | |
# Validate input is present and is 1-4 | |
[[ $1 && $1 != *[^1-4]* ]] || { echo "Invalid input." >&2; exit 1; } | |
# Free TTY from any process reading it | |
lsof -t /dev/ttyUSB0 | xargs -r kill -9 | |
# Set output to File Descriptor 3 | |
exec 3</dev/ttyUSB0 | |
# Set TTY parameters (baud rate, etc) | |
stty -F /dev/ttyUSB0 57600 raw -echo | |
# Send command to switch all out to in[1-4] | |
echo "EZS OUT0 VS IN$1" > /dev/ttyUSB0 | |
# Await a response from TTY | |
while [ "$response" = "" ]; do | |
# Read from FD3 and echo to STDOUT | |
read -e output <&3 | |
response=$(echo "$output") | |
echo $output | |
done | |
# Release FD3 | |
exec 3<&- | |
# Logging to STDOUT for review | |
echo "Expected OUT0 VS IN"$1 | |
echo "Received" $output | |
if [[ "$output" == *"OUT0 VS IN$1"* ]]; then | |
echo "Match!" | |
exit 0 | |
else | |
echo "Did not match." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment