Article View: borland.public.cppbuilder.nativeapi
Article #12954Re: ComPort Handling
From: John Scalco
Date: Sun, 09 Nov 2003 15:49
Date: Sun, 09 Nov 2003 15:49
64 lines
2637 bytes
2637 bytes
Another option is to use a component library: TurboPower's Asynch, which is
now an open source product
on SourceForge.net ?
it has a component, which generates these types of events and insulates you
from the low level handling details (that is if you want to be insulated
from these details <grin>)
just another option there,
hope that helps,
Sincerely,
J
"Michel Leunen" <mleu@STOPSPAMskynet.be> wrote in message
news:3facbd32$2@newsgroups.borland.com...
> Andre Letourneau wrote:
>
> > I would like to have a program respond to a character received on a
serial
> > port.
> > Is there a way to have a fonction called on a char. received without
having
> > to repetedly poll the port using
> > ReadFile() ??
>
> Look at overlapped file to read from your port asynchronously using
> events. There is an example in the win32 help file. Also Look for
> CreateEvent(), WaitCommEvent().
> Basically, you have to do something like this:
>
> CreateFile(...,FILE_FLAG_OVERLAPPED,...);
> ...
>
> CreateEvent(...);
> if(!ReadFile(...))
> {
> if(GetLastError() == ERROR_IO_PENDING) //the read operation could not
> be processed immediately
> {
> WaitForSingleObject(...); // wait until a char is received
> if(GetOverlappedResult(...)) // get the result of the overlapped
> operation
> {
> //OK, process with the char received
> }
> else
> {
> // Error
> }
> }
> // the character was received immediately
> }
>
> HTH
> Michel
> --
> ----------------------------------------
> Michel Leunen
> mailto:michel@leunen.com
> http://www.leunen.com/cbuilder/
> ----------------------------------------
>
Technical Details
Message-ID:
<3fae6184$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3fac1d1d$1@newsgroups.borland.com> <3facbd32$2@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,4130aea95ce8f144 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-11-09 08:09:15 PST From: "John Scalco" <jscalco@idealsw.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3fac1d1d$1@newsgroups.borland.com> <3facbd32$2@newsgroups.borland.com> Subject: Re: ComPort Handling Date: Sun, 9 Nov 2003 10:49:18 -0500 Lines: 66 Organization: Ideal Software, Inc. X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 68.18.2.125 Message-ID: <3fae6184$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1068392836 68.18.2.125 (9 Nov 2003 07:47:16 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail