[En-Nut-Discussion] UsartRead and timeout
Uwe Bonnes
bon at elektron.ikp.physik.tu-darmstadt.de
Tue Apr 25 11:25:10 CEST 2023
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 at embedded-it.de> 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 at elektron.ikp.physik.tu-darmstadt.de
Institut fuer Kernphysik Schlossgartenstrasse 9 64289 Darmstadt
--------- Tel. 06151 1623569 ------- Fax. 06151 1623305 ---------
More information about the En-Nut-Discussion
mailing list