Timeout on serial port read

"Gary S. Moss", VLD/VMB moss at BRL.MIL
Thu May 3 23:29:59 AEST 1990


< I am trying to set the ioctl call so that a raw read from a
< serial port will time out after a few seconds. No matter what I
< set the TIME value for in the control structure, the machine
< still hangs waiting for characters. What am I doing wrong, if anything.
<     new_settings.c_iflag = IGNBRK | IGNPAR;
<     new_settings.c_oflag = NULL;
<     new_settings.c_cflag = B9600 | CS8 | CREAD | CLOCAL;
<     new_settings.c_lflag = ICANON;
<     new_settings.c_line  = NULL;
<     new_settings.c_cc[0] = NULL;
<     new_settings.c_cc[1] = NULL;
<     new_settings.c_cc[2] = NULL;
<     new_settings.c_cc[3] = NULL;
<     new_settings.c_cc[4] = NULL;
<     new_settings.c_cc[5] = TIMEOUT;


For one thing, if you set ICANON, you will not get RAW input; do the
following instead.  Also, if you want to get 1 character at a time
without blocking, set the VMIN (element 4) of c_cc to 1, and set
TIMEOUT to 0.

new_settings.c_lflag &= ~ICANON;	/* Canonical input OFF. */
new_settings.c_cc[VMIN] = 1;
new_settings.c_cc[VTIME] = 0;

Other indices for c_cc should be written using their mnemonics as defined
in /usr/include/sys/termio.h for portability if nothing else.

CAVIAT: the VMIN/VTIME mechanism is intended for reading DMA bursts, and
does not really work for general timeouts.  What you probably need to
use poll(2) or select(2) rather than ioctl(2) (if I understand your
question).



More information about the Comp.sys.sgi mailing list