[En-Nut-Discussion] How to write character filter with timeout?

Ole Reinhardt ole.reinhardt at embedded-it.de
Fri Aug 21 14:20:57 CEST 2009


Hi Ulrich,

> _ioctl(_fileno(dev), UART_SETREADTIMEOUT, &t);

what's about the following code (more or less pseudo code)

u_long timeout = 500; // 500ms
u_long start_time;
u_long time_diff;
char   ch;

read_time = NutGetMillis();

while ((time_diff = NutGetMillis() - start_time) < timeout) {
	register u_long to = timeout - time_diff;
	_ioctl(_fileno(dev), UART_SETREADTIMEOUT, &to);
	ch = fgetc(dev);
	if (ch == the_char_to_search) break;
}

Bye,

Ole Reinhardt

-- 
 _____________________________________________________________
|                                                             |
| Embedded-IT                                                 |
|                                                             |
| Ole Reinhardt        Tel. / Fax:        +49 (0)271  7420433 |
| Luisenstraße 29      Mobil:             +49 (0)177  7420433 |
| 57076 Siegen         eMail:    ole.reinhardt at embedded-it.de |
| Germany              Web:         http://www.embedded-it.de |
|_____________________________________________________________|




More information about the En-Nut-Discussion mailing list