HI, I'm trying to test serial ports using a bash script. Currently I have:
DATA="1234567890abcdefghijklmnopqrstuvwxyz"
stty -F /dev/ttyS0 ispeed 115200 ospeed 115200 stty -F /dev/ttyS1 ispeed 115200 ospeed 115200
echo -n " Sending data from /dev/ttyS0 to /dev/ttyS1:" ./send_data.sh /dev/ttyS0 $DATA &
exec 3</dev/ttyS1 while read -t 2 -u 4 RESULT do if [[ "$RESULT" == "$DATA" ]] then echo " PASSED" else echo " FAILED" fi done
I repeat this script for data in the other direction.
This seems to work fine if a cable is connected between the two ports, and data transfers are successful. However, if the first time round, but if no cable is connected between ttyS0 and ttyS1, the first test reports FAILED, and then the script hangs.
BTW the send_data script is a follows:
sleep 1 echo $2 > $1 2>/dev/null
I thought the read -t 2 ... should timeout after 2 seconds if no data is received. Any idea why this hangs?
Also, is there a better way to test these ports? The system I am trying to test is limited - perl and awk are not installed.
Many thanks,
Stuart.