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.
Stuart Bailey stuart@linusoft.co.uk [...]
while read -t 2 -u 4 RESULT
[...]
I thought the read -t 2 ... should timeout after 2 seconds if no data is received. Any idea why this hangs?
Does that work other than when reading from a pipe or live terminal? The -u is pointing it at a file descriptor, so that might hang it.
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.
I can't think of one on that limited a system.
Hope that helps,
[...]
while read -t 2 -u 4 RESULT
[...]
I thought the read -t 2 ... should timeout after 2 seconds if no data is received. Any idea why this hangs?
Does that work other than when reading from a pipe or live terminal? The -u is pointing it at a file descriptor, so that might hang it.
I did some testing yesterday, and found that -t 2 does seem to work with file descriptors, even though the man page says it shouldn't (under bash 3.0). I tried removing the timeout, and the script hangs indefinitely at the first call to read - obviously waiting for data.
I think I'll have to accept that any hang of more that 2 seconds indicates a failure, and CRTL+C should be used.
Many thanks for the help.
Stuart.