Article View: borland.public.cppbuilder.nativeapi
Article #6460Re: Response not in que?
From: Bob Gonder
Date: Mon, 09 May 2005 22:26
Date: Mon, 09 May 2005 22:26
61 lines
3302 bytes
3302 bytes
Neil P. wrote:
> do
> {
> clComm.Read(1);
> cResponse = NULL;
Why the double assign?
> cResponse = clComm.cTransBuff;
> // Clear the buffers
> for (int i = 0; i <= (BUFSIZE - 1); i++)
> bCommData[i] = NULL;
// Clearer Clear the buffers
memset( bCommData, 0, sizeof(bCommData) );
> // Set a safety timeout
> dwRead_Time_Out = GetTickCount() + (iExpected*2);
The first data won't arrive for .001042 seconds, so you are leaving
only .000958 seconds for the device to get the character you sent and
respond. Also, realise that the counter isn't all that accurate to
begin with. Example: First call is at 1.001999 and shows 1.001, that
leaves you with less than 1 character-time before you time out.
To be fair to the device, you would need to allow 1.042 msec per
character sent, plus reasonable processing time, plus the same amount
times chars to receive. Also, some devices don't send at full baud
rate. I've see 50% duty cycles on some devices (one full char-time
between chars).
> while (bStop_Read == false)
> {
> // Clear any communication error & return # of bytes in the input
>buffer
> ClearCommError(hComm, &dwError, &comstat);
See other message.
> GetOverlappedResult(hComm,
> &o,
> &dwActualBytesRead,
> FALSE);
>
> // Are there bytes waiting and check if buffer is not overrun
> if ((dwActualBytesRead != 0) && (dwActualBytesRead <= BUFSIZE))
Not right. Can overflow cTransBuf. Also discards data and perhaps
causes timeout because you threw away the data you were waiting for.
> { // Begin if statement (actual bytes read)
>
> // Start the collection of bytes
> for (unsigned int i = 0; i <= (dwActualBytesRead - 1); i++)
> { // Begin for statement (byte collect)
>
> // Copy the data to the return variable
> cTransBuff[iCollectBytes++] = bCommData[i];
>
Technical Details
Message-ID:
<ainv71tis6a7m0pugjr1218hchvoha332j@4ax.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.nuthinbutnews.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<427fa27e@newsgroups.borland.com> <vugv711ona1kdbekucqqkg6csqkcd4agrd@4ax.com> <427fca8b$1@newsgroups.borland.com> <ukjv71lvb2s28pvi34r21cf1loa8nsqfnv@4ax.com> <427fd7cf$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,369fa724017da622 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: Bob Gonder <notbg@notmindspring.invalid> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Response not in que? Date: Mon, 09 May 2005 15:26:30 -0700 Organization: MindSpring Enterprises, Inc. Reply-To: notbg@notmindspring.invalid Message-ID: <ainv71tis6a7m0pugjr1218hchvoha332j@4ax.com> References: <427fa27e@newsgroups.borland.com> <vugv711ona1kdbekucqqkg6csqkcd4agrd@4ax.com> <427fca8b$1@newsgroups.borland.com> <ukjv71lvb2s28pvi34r21cf1loa8nsqfnv@4ax.com> <427fd7cf$1@newsgroups.borland.com> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 67.77.41.187 X-Trace: newsgroups.borland.com 1115677587 67.77.41.187 (9 May 2005 15:26:27 -0700) Lines: 62 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!news-in.nuthinbutnews.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail