Article View: borland.public.cppbuilder.nativeapi
Article #3470Re: Com port error
From: Remy Lebeau (TeamB)
Date: Thu, 15 Jun 2006 18:26
Date: Thu, 15 Jun 2006 18:26
49 lines
2407 bytes
2407 bytes
"JD" <nospam@nospam.com> wrote in message
news:4491a4c2$1@newsgroups.borland.com...
> The problem that I'm having is that I want the thread to use
> WaitCommEvent which means that when I open the port using
> CreateFile, I must specify FILE_FLAG_OVERLAPPED for the
> dwFlagsAndAttributes parameter.
Not true. WaitCommEvent() works on non-overlapped ports as well. If you do
not specify FILE_FLAG_OVERLAPPED, then you have to pass NULL to any function
that has an OVERLAPPED parameter.
> When the port is opened this way, WriteFile fails with an error
> code of 997 which translates to "Overlapped I/O operation is in
> progress".
As it should be. 997 is ERROR_IO_PENDING. That is not an error. You just
need to call GetOverlappedResult() to wait for the actual work to finish,
ie:
DWORD dwWritten;
if( !WriteFile(hPort, ..., &dwWritten, &overlapped) )
{
if( GetLastError() != ERROR_IO_PENDING )
{
// an actual error occured, do something ....
return;
}
GetOverlappedResult(hPort, &overlapped, &dwWritten, TRUE);
}
// use dwWritten as needed ...
The thing about GetOverlappedResult() is that you can set the bWait
parameter to FALSE instead if you want to go do other things while you wait
for the data to be written, ie:
write to port ...
do some work ...
check overlapped result ...
do some more work ...
check overlapped result ...
etc ...
Gambit
Technical Details
Message-ID:
<4491a6b2$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.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:
<4491a4c2$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,f1782b94b4ced041,start X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <4491a4c2$1@newsgroups.borland.com> Subject: Re: Com port error Date: Thu, 15 Jun 2006 11:26:35 -0700 Lines: 51 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <4491a6b2$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1150396082 68.69.17.41 (15 Jun 2006 11:28:02 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.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