Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How i can read tty file with timeout?

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

like image 276
Denys Rogovchenko Avatar asked Jul 15 '11 22:07

Denys Rogovchenko


1 Answers

You can use the program stty to configure the tty device. To see the settings for terminal /dev/ttyS0, try

stty -a -F /dev/ttyS0

The default settings regarding timeout are min = 1; time = 0, which means that the reading program will read until at least one character has been read and there is no timeout. Using e.g.

stty -F /dev/ttyS0 min 0 time 10

the reading program (e.g. cat) will finish reading after one second whether anything has been read or not. The unit for the parameter time is tenths of a second; you can check out man stty for more information.

like image 196
Antti Avatar answered Sep 23 '22 17:09

Antti