Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2022-09

SerReadTimeout question

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

James Richters

I can't seem to find any documentation or SerRead or SerReadTimeout.. searching for either along with Freepascal doesn't get me any results. If it exists somewhere and I am just missing it, can someone tell me where it is?

Anyway, what I'm trying to figure out is when the timeout timer starts... does the timeout timer start when I call the funciton, or does it start when there is no data to read... waiting for a certain amount of time to see if there is more data? Of course it will also stop when the requested number of bytes is satisfied.

I'm trying to read as fast as reliable, but I don't always know how many bytes I'm expecting. So it would be handy it the timer started when there was nothing to read.. then I could have a very small timeout and as long as data was coming in, I would get it, until the requested number of bytes is reached... but if the timer stated when I call the function, I will have to caclculate how long it should take and add a little in case the data isn't ready when I ask for it.

James

Christo Crause
to James Richters

On Mon, 19 Sep 2022, 03:18 James Richters via fpc-pascal, <

Show quoted text 9 lines
wrote: I can't seem to find any documentation or SerRead or SerReadTimeout.. searching for either along with Freepascal doesn't get me any results. If it exists somewhere and I am just missing it, can someone tell me where it is? Anyway, what I'm trying to figure out is when the timeout timer starts...

FPC uses the OS provided functionality to interact with the serial port. On Windows the timeout seems to start when the read request is made ( https://learn.microsoft.com/en-us/previous-versions/ff547486(v=vs.85)). On POSIX (at least Linux) it depends on the specific set of flags specified , scroll down to the discussion on canonical/noncanonical mode for the details (https://linux.die.net/man/3/termios).

Christo Crause
to Christo Crause: On Mon, 19 Sep 2022, 03:18 James Richters via fpc-pascal, < FPC uses the OS provided…
AM Christo Crause wrote 20 lines
On Mon, 19 Sep 2022, 03:18 James Richters via fpc-pascal, < > wrote: > I can't seem to find any documentation or SerRead or SerReadTimeout.. > searching for either along with Freepascal doesn't get me any results. > If it exists somewhere and I am just missing it, can someone tell me where > it is? > > Anyway, what I'm trying to figure out is when the timeout timer starts... > FPC uses the OS provided functionality to interact with the serial port. On Windows the timeout seems to start when the read request is made ( https://learn.microsoft.com/en-us/previous-versions/ff547486(v=vs.85)). On POSIX (at least Linux) it depends on the specific set of flags specified , scroll down to the discussion on canonical/noncanonical mode for the details (https://linux.die.net/man/3/termios).

A bit more information after peeking into the source code: on win32 the timeout information can be read or set using Get/SetCommTimeouts. The COMMTIMEOUTS structure (
https://learn.microsoft.com/en-us/windows/win32/api/winbase/ns-winbase-commtimeouts) contains a read interval timeout and total timeouts for read & write operations. SerReadTimeout sets the ReadTotalTimeoutConstant value, so basically the total timeout duration.

On Linux SerReadTimeout uses a fpSelect on the handle with the specified timeout, so in principle it is the same behaviour as on Windows, i.e. a total timeout.

While both OSs provide some functionality to specify inter character timeouts, FPC does not directly expose this functionality in the Serial unit.