🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: ComPort Handling

#12947
From: Michel Leunen
Date: Sat, 08 Nov 2003 09:53
44 lines
2125 bytes
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: <3facbd32$2@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-mail
References: <3fac1d1d$1@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-08 02:09:08 PST
Date: Sat, 08 Nov 2003 10:53:50 +0100
From: Michel Leunen <mleu@STOPSPAMskynet.be>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5) Gecko/20031007
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: ComPort Handling
References: <3fac1d1d$1@newsgroups.borland.com>
In-Reply-To: <3fac1d1d$1@newsgroups.borland.com>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 80.200.28.61
Message-ID: <3facbd32$2@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1068285234 80.200.28.61 (8 Nov 2003 01:53:54 -0700)
Lines: 45
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