Article View: borland.public.cppbuilder.nativeapi
Article #2290Re: Slow Read From Serial Port
From: Phil
Date: Wed, 21 Mar 2007 13:01
Date: Wed, 21 Mar 2007 13:01
101 lines
3679 bytes
3679 bytes
Michel,
Thank you for your reply.
You wrote:
> You read one byte at a time. Why don't you read all bytes available in the
> queue?
I understand your point here, and I could change my code to read all of the
bytes at once, but that is not what is causing the delay. The delay is
caused by the call to GetOverlappedResult(). If I do a read of 4 bytes, the
function is called 4 times. The first time through, I see the delay at the
GetOverlappedResult call, but for the next 3 bytes, the ReadFile() is
successful, so GetOverlappedResult does not get called, and the delay does
not occur.
> if(!ReadFile(hCom,buffer,numbyte,&BytesRead,&OvlRead))
> {
> if(GetLastError() == ERROR_IO_PENDING)
> {
> if(WaitForSingleObject(OvlRead.hEvent,5000))
> {
> BytesRead = 0;
> }
> else
> {
> GetOverlappedResult(hCom,&OvlRead,&BytesRead,false);
> OvlRead.Offset += BytesRead;
> }
> }
> else BytesRead = 0;
> }
I tried this approach as well. Just like before, when I'm connected
directly with a serial cable the communications are fast. However, when I
use my modem, I still see a delay of about 125ms. However, this time it is
in the WaitForSingleObject() function.
To me it looks like the delay occurrs when the modem signals to the
operating system that a byte has arrived. I'm just not sure if there is a
way to speed it up.
Phil
"Michel Leunen" <nospam@noreply.be> wrote in message
news:46004649$1@newsgroups.borland.com...
> Phil wrote:
>
>> if (!ReadFile(hcomm, xbyte, 1, &ibytes, &overlapped))
>
> You read one byte at a time. Why don't you read all bytes available in the
> queue?
>
>> while ((!ibytes) &&
>> (clock() < (int)timeout) &&
>> ((ierr == ERROR_IO_PENDING) ||
>> (ierr == ERROR_IO_INCOMPLETE)))
>
> You don't need to put this in a while loop and why don't you use
> WaitForSingleObject() with the overlapped struct event to get your
> timeout?
>
> I personnaly do something like this:
>
> if(!ReadFile(hCom,buffer,numbyte,&BytesRead,&OvlRead))
> {
> if(GetLastError() == ERROR_IO_PENDING)
> {
> if(WaitForSingleObject(OvlRead.hEvent,5000))
> {
> BytesRead = 0;
> }
> else
> {
> GetOverlappedResult(hCom,&OvlRead,&BytesRead,false);
> OvlRead.Offset += BytesRead;
> }
> }
> else BytesRead = 0;
> }
>
> HTH
> Michel
> --
> ----------------------------------------
> Michel Leunen
> mailto: see my homepage.
> C++Builder, BCC5.5.1 Web site:
> http://www.leunen.com/
> ----------------------------------------
Technical Details
Message-ID:
<46012cbd$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<46002b03$1@newsgroups.borland.com> <46004649$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,d1cd2b38aa5bb326 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Phil" <phil@camusinc.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <46002b03$1@newsgroups.borland.com> <46004649$1@newsgroups.borland.com> Subject: Re: Slow Read From Serial Port Date: Wed, 21 Mar 2007 09:01:42 -0400 Lines: 103 Organization: Camus X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3028 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 NNTP-Posting-Host: 216.54.107.58 Message-ID: <46012cbd$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1174482109 216.54.107.58 (21 Mar 2007 06:01:49 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail