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

Ulrich Prinz uprinz2 at netscape.net
Thu Aug 20 22:48:33 CEST 2009


Hi Harald!

But that doesn't solve my problem. If I wait a certain time on fgetc() I 
miss characters that arrived after the one that is returned.
If I use it in a loop, the timeout of fgetc() must be added to the 
NutSleep() ammount. But also then I miss characters, possibly containing 
the one I search for.

The only solution might be, to set the timeout of fgtec() to 0 and read 
as long as not -1 is returned and feof() returns EOF...

...
It seems to work. I set the timeout to 1ms and count down my timeout on 
any EOF condition. Going that way means, that any received character 
will not decrement the timeout as I cannot find out after what part of 
the timeout the character occured. So any character extends the timout.

Its ok for now, but is there any other way without breaking into the 
driver structure? A routine like fsize( ) could help, to distinguish the 
filesize / rx-buffer size of a stream device.

Best regards, Ulrich

Harald Kipp wrote:
> Hi Ulrich,
> 
> Ulrich Prinz wrote:
> 
>> _ioctl(_fileno(dev), UART_SETREADTIMEOUT, &t);
> ...
>> Is there a non-blocking function for fgetc() or do I have to do stream 
>> parsing or is there any easier way?
> 
> When you set a read timeout on a specific device, then the related
> fgetc() on that device will be non-blocking. When -1 is returned, you
> can use feof() or ferror() to distinguish between timeout (end of file)
> or error.
> 
> http://beej.us/guide/bgc/output/html/multipage/feof.html
> 
> Harald
> 
> _______________________________________________
> http://lists.egnite.de/mailman/listinfo/en-nut-discussion



More information about the En-Nut-Discussion mailing list