Article View: borland.public.cppbuilder.nativeapi
Article #6261Re: Problem with serial communications
From: Bob Gonder
Date: Tue, 31 May 2005 14:57
Date: Tue, 31 May 2005 14:57
38 lines
2216 bytes
2216 bytes
Martin Nijhoff wrote:
>Some time ago I wrote a serial port component using overlapped I/O. The
>component creates a thread to monitor the serial port an trigger some event
>handlers.
>
>The component works fine on both Win98 and WinXP, that is, most of the time.
>Sometimes an error occurs while writing to the serial port, in which case
>the WriteFile() fails and GetLastError() returns ERROR_OPERATION_ABORTED
>(995).
You removed some code. Did any of that code contain CancelIO() ?
You didn't show osRead or osWrite.
Your class has One OVERLAPPED struct, not 2, and you wait on 2 events.
I would think you would want to wait on 3 events, evRead, evWrite and
evTerminate
You are blocking after read and write, so why are you using overlapped
instead of blocking i/o?
You aren't handling any errors from ReadFile() or WriteFile().
>DWORD __fastcall TCustomCOMPort::Write (void *Buffer, DWORD Size)
>{
> DWORD BytesWritten;
>
> if (FHandle == INVALID_HANDLE_VALUE)
> throw Exception(SPortClosed);
>
> if (!WriteFile(FHandle, Buffer, Size, &BytesWritten, &osWrite))
> {
> if (GetLastError() == ERROR_IO_PENDING)
> WaitForAsync(osWrite, BytesWritten);
> }
> return(BytesWritten);
>}
Technical Details
Message-ID:
<sito91h41an986u4069q49ocejmgt29ae5@4ax.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<429c30e1$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,ab642e2ba4263114 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: Problem with serial communications Date: Tue, 31 May 2005 07:57:52 -0700 Organization: MindSpring Enterprises, Inc. Reply-To: notbg@notmindspring.invalid Message-ID: <sito91h41an986u4069q49ocejmgt29ae5@4ax.com> References: <429c30e1$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.154.209 X-Trace: newsgroups.borland.com 1117551470 67.77.154.209 (31 May 2005 07:57:50 -0700) Lines: 40 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news2.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail