zebada
asked on
WaitCommEvent failing
I have the following code segents in my app:
ovlap: OVERLAPPED;
...
ovlap.hEvent := CreateEvent(nil,true,false ,PChar('VP W'));
...
SetCommMask(fd,EV_DSR);
...
fd := CreateFile(PChar(Name),GEN ERIC_READ+ GENERIC_WR ITE,0,nil, OPEN_EXIST ING,FILE_A TTRIBUTE_N ORMAL+FILE _FLAG_OVER LAPPED,0);
if ( fd=INVALID_HANDLE_VALUE ) then
Raise EVpw.CreateFmt('Can''t open %s. %s',[Name,WinMsg(GetLastEr ror)]);
...
if ( not WaitCommEvent(fd,flag,@ovl ap) ) then
begin
err := GetLastError;
if ( err<>ERROR_IO_PENDING ) then
Raise EVpw.CreateFmt('WaitCommEv ent(~DSR) failed for %s. %s',[Name,WinMsg(err)]);
state := WaitForSingleObject(ovlap. hEvent,10) ;
...
The call to WaitCommEvent returns FALSE and
err is set to 87="The parameter is incorrect".
Can anyone tell me why and how to fix it?
ovlap: OVERLAPPED;
...
ovlap.hEvent := CreateEvent(nil,true,false
...
SetCommMask(fd,EV_DSR);
...
fd := CreateFile(PChar(Name),GEN
if ( fd=INVALID_HANDLE_VALUE ) then
Raise EVpw.CreateFmt('Can''t open %s. %s',[Name,WinMsg(GetLastEr
...
if ( not WaitCommEvent(fd,flag,@ovl
begin
err := GetLastError;
if ( err<>ERROR_IO_PENDING ) then
Raise EVpw.CreateFmt('WaitCommEv
state := WaitForSingleObject(ovlap.
...
The call to WaitCommEvent returns FALSE and
err is set to 87="The parameter is incorrect".
Can anyone tell me why and how to fix it?
ASKER
Hi inthe,
An example would be great.
I have found that I don't get the error on the first few times. Only after I have called WaitCommEvent maybe three or four times. If I put a SetCommMask before WaitCommEvent then I don't get any errors - because SetCommMask will clear any pending waits. I think it might be something to do with the fact that I might be trying to wait on an event that I am already waiting on, if you know what I mean.
An example would be great.
I have found that I don't get the error on the first few times. Only after I have called WaitCommEvent maybe three or four times. If I put a SetCommMask before WaitCommEvent then I don't get any errors - because SetCommMask will clear any pending waits. I think it might be something to do with the fact that I might be trying to wait on an event that I am already waiting on, if you know what I mean.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Barry,
By looking at the code I figured out where I was going wrong.
Thanks.
By looking at the code I figured out where I was going wrong.
Thanks.
i cant see why your getting that error but if you want i have an example of waiting for an event on the comport using WaitComEvent(),WaitForSing