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 52
|
SetCommMask(g_hCOM,EV_RXCHAR);
memset(&ov,0,sizeof(ov));
ov.hEvent = CreateEvent( 0,true,0,0);
while(1)
{
int iSomme = 0;
char* pPoint = NULL;
BOOL bwait =TRUE ;
Sleep(100);
bSucces1 = 0;
WaitCommEvent( g_hCOM, &dwEvtMask, &ov);
bwait = WaitForSingleObject(ov.hEvent ,INFINITE);
if(bwait == WAIT_OBJECT_0)
{
printf("ok\n");
bSucces1 = ReadFile(g_hCOM, pBuffer, 14, &dwBytesRead, &ov);
if(bSucces1 == 1)
{
if(*(pBuffer+1)&(1<<0))
{
iSomme += pow(2,3);
};
iSomme+=*(pBuffer+2)>>5 &0x07;
int iTeste = 0;
iTeste = *(pBuffer+iSomme+4)<<4 & 0x70;
iTeste+= *(pBuffer+iSomme+5)>>4 & 0x0F;
}
if(iTeste == 127)
{
printf("packet valide \n");
}
else
{
printf("packet non valide\n");
}
}
}
} |
Partager