Hi all
That I'm working on the serial port win32 api and I must, my liaison with asynchronous read character go once they are received on the serial port.
so I wrote this code.
C + + code:
Code:
# include <windows.h>
# include <assert.h>
# include <stdlib.h>
# include <conio.h>
# include <stdio.h>
# include <vcl.h>
# pragma hdrstop
//------------------------------------------------ ---------------------------
# pragma argsused
int main (int argc, char * argv [])
(
Overlapped over;
HANDLE hComm;
DWORD EventMask;
hComm = CreateFile ( "COM1", GENERIC_WRITE | GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
if (hComm == INVALID_HANDLE_VALUE) (
printf ( "Error opening port");
Else ()
if (SetCommMask (hComm, EV_RXCHAR)) (
over. hEvent = CreateEvent (
NULL,
TRUE,
FALSE,
NULL);
over. Internal = 0;
over. InternalHigh = 0;
over. Offset = 0;
over. OffsetHigh = 0;
assert (over.a hEvent);
while (true) (
if (WaitCommEvent (hComm, & EventMask, & over)) (
if (EventMask & EV_RXCHAR) (
printf ( "character received");
getch ();
)
)
else (
printf ( "Error% d", GetLastError ());
getch ();
)
)
Else ()
printf ( "error creation event% d", GetLastError ());
)
) Getch ();
return 0;
)
Outside I have a big problem, waitcommevent me always returns 0, so the error getlast I watch what I can and if I take it in my loop I have something like
Error 997 ERROR_IO_PENDING
Error 87 ERROR_INVALID_PARAMETER
So now it's been a good time am with the forums and but I can not find anything so I put my query here.
If you have an genius idea please let me know.
(in case I test the connection with hyperterminal no problem 2)
Bookmarks