I came across the following set of shell commands for reading and writing to serial ports, from this thread:
stty -speed 19200 < /dev/ttyS0 # sets the speed of the port
exec 99<>/dev/ttyS0 (or /dev/ttyUSB0...etc)
printf "AT\r" >&99
read answer <&99 # this reads just a CR
read answer <&99 # this reads the answer OK
exec 99>&-
I am having trouble understanding the lines that use file descriptors, particularly these two lines:
exec 99<>/dev/ttyS0 (or /dev/ttyUSB0...etc)
and
exec 99>&-
What are they doing? Is there any reason why 99
is being used as opposed to any other number? Any help is appreciated. Thanks!
99
; that was just "a file descriptor that we are pretty sure won't be in use". – larsks Jul 21 '22 at 17:51