1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| //---------------------------------------------------------------------------
#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("Erreur d'ouverture de 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.hEvent);
while (true){
if (WaitCommEvent(hComm,&EventMask,&over)){
if (EventMask & EV_RXCHAR){
printf("caractère reçus");
getch();
}
}
else {
printf("Error %d",GetLastError());
getch();
}
}
} else {
printf("erreur creation event %d",GetLastError());
}
} getch();
return 0;
}
//--------------------------------------------------------------------------- |
Partager