Re: UsartRead and timeout
Uwe Bonnes <bon-1JbLm1bU5j5ZIx36JBfelj3+ndqKAYMe9FMPySWZwLkb1SvskN2V4Q@public.gmane.org> Tue, 25 Apr 2023 11:25:10 +0200
| Newsgroups | gmane.comp.hardware.microcontrollers.ethernut |
|---|---|
| Message-ID | <[email protected]> |
Hi, okay, the implementation does not contradict the specs. And I already implemented reading in a loop. Thanks for the feedback Uwe >>>>> "Ole" == Ole Reinhardt <ole.reinhardt-L1vi/[email protected]> writes: Ole> Hi Uwe, yes I would expect this behavior to be correct. Ole> The UsartRead() routine will normally be called by read() Ole> from the c-library. Ole> read() is defined to return the currently available number of Ole> bytes, which may be lower than the requested amount. Ole> See e.g. https://man7.org/linux/man-pages/man2/read.2.html Ole> When writing a parser, that reads data from a device, I would Ole> normally use a loop, that calls read() until the expected Ole> amount of data is received. If you do not know the number of Ole> bytes that shall be received, just implement an timeout, Ole> until which the first character shall be received and then an Ole> interbyte timeout, until which the next character) shall be Ole> received. Ole> I would use the select() routine to implement these timeouts. Ole> Best regards, Ole> Ole Reinhardt Ole> Am 24.04.23 um 19:28 schrieb Uwe Bonnes: >> Hello, >> >> ../../dev/usart.c in UsartRead reads: 228 /* 229 * Wait until >> at least one character is buffered or until a read 230 * >> timeout occured. 231 */ >> >> Is this really the intended behaviour? I would expect to read >> like >> >> * Wait until the requested number of character is buffered or >> until a read * timeout occured. >> >> This would be in line with e.g. >> https://learn.microsoft.com/en-us/windows-hardware/drivers/serports/setting-read-and-write-timeouts-for-a-serial-device" >> "Serial.sys continues to transfer bytes until the requested >> number of bytes are transferred or a time-out event occurs." >> >> Returning after the first received byte makes it hard to wait >> for the full multi-byte answer of an external device. >> >> What is your opinion? >> >> Thanks Ole> _______________________________________________ Ole> http://lists.egnite.de/mailman/listinfo/en-nut-discussion -- Uwe Bonnes bon-1JbLm1bU5j5ZIx36JBfelj3+ndqKAYMe9FMPySWZwLkb1SvskN2V4Q@public.gmane.org Institut fuer Kernphysik Schlossgartenstrasse 9 64289 Darmstadt --------- Tel. 06151 1623569 ------- Fax. 06151 1623305 --------- _______________________________________________ http://lists.egnite.de/mailman/listinfo/en-nut-discussion