Board index » delphi » difference beetween Waitcomevent Win95/98 and WinNT ???

difference beetween Waitcomevent Win95/98 and WinNT ???

Good morning from,
I have a problem with and event from a COM PORT

After to have create my com port with the following code :

****** HandlePort:=CreateFile(
******  port,GENERIC_READ and GENERIC_WRITE,
******  0,0,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,0);

And init the comport with a correct DCB , i set the mask under the PORT via
:

****** SetCommMask(HandlePort, EV_RLSD); {to recept an RLSD event}

create an event via :

******ov.hEvent := CreateEvent(nil,TRUE,FALSE,Nil); {with  ov : OVERLAPPED}

 and wait the event :

***** WaitCommEvent(HandlePort,ov.hEvent,@ov);

This code all ready under windows95/98, it is right and the event is
correctly catch the WaitCommEvent function return always true
 but the function WaitCommEvent return always false under WindowsNT ???

If anyone can help me Pleased....

Thanks...

 

Re:difference beetween Waitcomevent Win95/98 and WinNT ???


In article <8m7dhk$9d...@front6.grolier.fr>, "Anna Dolguikh"

Quote
<ceda...@club-internet.fr> writes:
>After to have create my com port with the following code :

>****** HandlePort:=CreateFile(
>******  port,GENERIC_READ and GENERIC_WRITE,
>******  0,0,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,0);

>And init the comport with a correct DCB , i set the mask under the PORT via
>:

>****** SetCommMask(HandlePort, EV_RLSD); {to recept an RLSD event}

>create an event via :

>******ov.hEvent := CreateEvent(nil,TRUE,FALSE,Nil); {with  ov : OVERLAPPED}

> and wait the event :

>***** WaitCommEvent(HandlePort,ov.hEvent,@ov);

>This code all ready under windows95/98, it is right and the event is
>correctly catch the WaitCommEvent function return always true
> but the function WaitCommEvent return always false under WindowsNT ???

I'm not sure why it returns true <gg>. My understanding is that Create Event
creates an event object whose handle is stored in the OverlappedStatus.hEvent
element. The second parameter of WaitCommEvent is a DWord which receives a mask
for the type of event which happened. Because you are waiting for only an RLSD
event only one type of event can happen, but if one has to wait for a number of
events then one has to test this DWord to establish what evented. You appear to
have overwritten the handle of the event object - to use a technical phrase, it
has been "{*word*81}ed up" <g>.

A couple of notes :-
1 I found that one had to initialise the port by using GetCommState and
SetCommState(HComm, DCB) otherwise the port did nothing.

2 I used a thread to watch the port which could time-out and be reset, or was
re-initialised if an event happened. When an event occurs one has to
WaitCommEvent again, but not if the thread times out.

3 When an event happened one then has to immediately GetCommModemStatus to see
what the value of the ocurring event was (ie has it changed to high or changed
to low).

Dealing with commports and watching them reminds me of the early Dungeons and
Dragons - full of "little twisty passages" <gg>.

Alan Lloyd
alangll...@aol.com

Re:difference beetween Waitcomevent Win95/98 and WinNT ???


I used WaitForSingleObject in a COM thread - this seemed like the best
way to avoid WaitCommEvent pegging the CPU, it worked OK on 95/98 and
NT.
try
  // Wait for 3 secs for a character to arrive at the port
    WaitCommEvent(hComm, EventMask, posWait);     // overlapped
    dwResult := WaitForSingleObject(posWait.hEvent, 3000);
    case dwResult of
      WAIT_OBJECT_0 :     // Operation completed
      begin
        if not GetOverlappedResult(hComm, osWait, NumRead,
          False) then
          // GetOverlappedResult returns FALSE if error
          raise ECOMError.Create('WaitCommEvent completed, but ' +
            'GetLastError returned ' + IntToStr(GetLastError))
      end;

      WAIT_TIMEOUT : // nothing arrived after 3 secs
        raise ECOMError.Create('WaitCommEvent timed out after 3 secs')
      else raise ECOMError.Create('WaitCommEvent didn''t succeed or '
+
        ' time out');
    end // case
  except on ECOMError do
    HandleError(2);  // Comm Timeout
  end;  // try

On Tue, 1 Aug 2000 23:06:59 +0200, "Anna Dolguikh"

Quote
<ceda...@club-internet.fr> wrote:
>Good morning from,
>I have a problem with and event from a COM PORT

>After to have create my com port with the following code :

>****** HandlePort:=CreateFile(
>******  port,GENERIC_READ and GENERIC_WRITE,
>******  0,0,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,0);

>And init the comport with a correct DCB , i set the mask under the PORT via
>:

>****** SetCommMask(HandlePort, EV_RLSD); {to recept an RLSD event}

>create an event via :

>******ov.hEvent := CreateEvent(nil,TRUE,FALSE,Nil); {with  ov : OVERLAPPED}

> and wait the event :

>***** WaitCommEvent(HandlePort,ov.hEvent,@ov);

>This code all ready under windows95/98, it is right and the event is
>correctly catch the WaitCommEvent function return always true
> but the function WaitCommEvent return always false under WindowsNT ???

>If anyone can help me Pleased....

>Thanks...

Other Threads