Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uunet!mcsun!cernvax!chx400!sgzh!root From: root@sgzh.uucp (Bruno Pape) Newsgroups: comp.sys.sgi Subject: Re: Timeout on serial port read Message-ID: <1990May4.161343.1945@sgzh.uucp> Date: 4 May 90 16:13:43 GMT References: <9005030929.aa08086@VMB.BRL.MIL> Reply-To: root@sgzh.UUCP (Bruno Pape) Organization: Silicon Graphics S.A., Zuerich, Switzerland Lines: 53 In article <9005030929.aa08086@VMB.BRL.MIL> moss@BRL.MIL ("Gary S. Moss", VLD/VMB) writes: >< 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). While the above is along the right path it too will hang forever waiting for one character. If he wants it to time out at some point I believe the following would work better. Replace delay with the number of seconds you want it to wait before timing out. tty.c_iflag = 0; tty.c_oflag = 0; tty.c_cflag = B9600 | CS8 | CREAD; tty.c_lflag = 0; tty.c_cc[VTIME] = delay; tty.c_cc[VMIN] = 0; if ( ioctl( descriptor, TCSETA, &tty ) < 0 ) perror("ioctl"); Bruno With 999999 possiblities between "cooked" and "raw" you know you're not going to have any fun. Boo hoo.