So I am trying to send a serial command to an embedded device and get a response for our test automation, I tried using cat as the following code, and gets stuck on the cat command, same goes for dd, and I also tried the solution posted in this link to no avail. I want to send a command, receive a reply, and do something with the reply non blocking. Maybe Bash has something similar to Select() in C? Or if anybody has a more elegant solution I would appreciate it immensely :)
#!/bin/bash
#tty=/dev/tps21
stty -F /dev/tps21 speed 38400 cs8 cread clocal -cstopb -parenb >> /dev/null
echo 1
echo 'loglevel off' > /dev/tps21
echo 2
cat < /dev/tps21 >> /dev/null #Gets stuck here
echo 3
echo 'shell <username> <password> /opt/tools/eeprom/read.sh wifi_apn' > /dev/tps21
echo 4
echo 5
apn_raw="$(cat < /dev/tps21)" #Gets Stuck here
echo 6
apn="$(echo "$apn_raw" | sed -n 3p)"
echo 7
echo "${apn}"
echo 8
echo 'shell <username> <password> /opt/tools/eeprom/read.sh wifi_pass' > /dev/tps21
pass_raw="$(cat -v < /dev/tps21)" #Gets Stuck here
pass="$(echo "$pass_raw" | sed -n 3p)"
echo "${pass}"
nmcli --nocheck d $apn connect $apn password $pass iface wlan0