Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SetCommTimeouts not working

677 views
Skip to first unread message

Anthony Gallagher

unread,
Feb 5, 2003, 11:20:32 PM2/5/03
to
Hello,

I can't seem to get the SetCommTimeouts function to work. If I
understand correctly, I should be able to set the timeout so that the
functions ReadFile and WriteFile will return after the specified amount
of time? My function is doing the following:

extern "C" bool WINAPI CommPortTimeouts(HANDLE cComPort, unsigned int
readTime, unsigned int writeTime)
{
COMMTIMEOUTS ct;

ct.ReadTotalTimeoutConstant = readTime;
ct.WriteTotalTimeoutConstant = writeTime;

return (bool)SetCommTimeouts(cComPort, &ct);
}

The function invariably returns true, but ReadFile still hangs. Not sure
what I could be doing wrong...

Thanks for any responses,

Anthony

Leo Havmøller

unread,
Feb 6, 2003, 1:07:36 AM2/6/03
to
"Anthony Gallagher" <anth...@cs.cmu.edu.nospam> wrote in message
news:3E41E290...@cs.cmu.edu.nospam...

> Hello,
>
> I can't seem to get the SetCommTimeouts function to work. If I
> understand correctly, I should be able to set the timeout so that the
> functions ReadFile and WriteFile will return after the specified amount
> of time? My function is doing the following:
>
> extern "C" bool WINAPI CommPortTimeouts(HANDLE cComPort, unsigned int
> readTime, unsigned int writeTime)
> {
> COMMTIMEOUTS ct;
>
> ct.ReadTotalTimeoutConstant = readTime;
> ct.WriteTotalTimeoutConstant = writeTime;

There are five fields in COMMTIMEOUTS. You only fill in two of them thus the
rest have random values.
Look up COMMTIMEOUTS in the MSDN library.

Leo Havmøller.


arkadyf

unread,
Feb 6, 2003, 1:26:36 AM2/6/03
to
OTOH pay attention that it not TO of ReadFile/WriteFile but symbol on line.
Arkady

"Leo Havmøller" <leh@-nospam-rtx.dk> wrote in message
news:#JUY$XazCHA.1628@TK2MSFTNGP10...

Tonu Aas

unread,
Feb 6, 2003, 5:49:28 AM2/6/03
to
> > COMMTIMEOUTS ct;
> >
> > ct.ReadTotalTimeoutConstant = readTime;
> > ct.WriteTotalTimeoutConstant = writeTime;
>
> There are five fields in COMMTIMEOUTS. You only fill in two of them thus
the
> rest have random values.
> Look up COMMTIMEOUTS in the MSDN library.

Filling all the fields can help you, but beware that not all timeout
values can be set to whatever value.
For LPTx there are some restrictions, but they are described nowhere, so use
DDK sources and help.

Tõnu.


Anthony Gallagher

unread,
Feb 6, 2003, 6:41:32 AM2/6/03
to
Thanks, Leo.

Alexander Grigoriev

unread,
Feb 6, 2003, 11:50:39 PM2/6/03
to
ReadTotalTimeout sets time after the _first_ character is received. You want
to set also ReadTimeoutMultiplier.

"Anthony Gallagher" <anth...@cs.cmu.edu.nospam> wrote in message
news:3E41E290...@cs.cmu.edu.nospam...

0 new messages