How can I read a tty file with a timeout?

I have a tty device in / dev where I send AT commands. I want to read line by line and stop reading the file after a timeout.

+4
source share
1 answer

You can use the stty program to configure the tty device. To view the terminal settings / dev / ttyS 0, try

stty -a -F /dev/ttyS0

Default settings for timeout min = 1; time = 0 min = 1; time = 0 , which means that the reader will be read until at least one character is read and there is no timeout. Use for example

stty -F /dev/ttyS0 min 0 time 10

a reader (such as cat ) will finish reading after one second whether it was read or not. The unit of time is a tenth of a second; you can check man stty for more info.

+3
source

All Articles