🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #2285

Re: Slow Read From Serial Port

#2285
From: Michel Leunen
Date: Tue, 20 Mar 2007 20:38
43 lines
2043 bytes
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: <46004649$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-mail
References: <46002b03$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
Date: Tue, 20 Mar 2007 21:38:53 +0100
From: Michel Leunen <nospam@noreply.be>
Organization: www.leunen.com
User-Agent: Thunderbird 1.5.0.10 (Windows/20070221)
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Slow Read From Serial Port
References: <46002b03$1@newsgroups.borland.com>
In-Reply-To: <46002b03$1@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 81.243.106.54
Message-ID: <46004649$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1174423113 81.243.106.54 (20 Mar 2007 13:38:33 -0800)
Lines: 43
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