发表于:2005/4/15 15:45:00
#0楼
UINT ComReceiveProc(LPVOID lpParam)
{
char buf2[100], buf1[100];
unsigned char buf3[50];
int len,len0;
int i,j,m;
unsigned int iCode;
static bool bOrder;
bOrder=FALSE;
m=0;
while (m_bSend)
{
wait: len0=sio_iqueue(iPort);
if (len0<100)
{
Sleep(50);
goto wait;
}
if (bOrder)
{
sio_read( iPort, buf1, 65);
for (i=0;i<40;i++)
buf2[i]=buf1[25+i];
}
else
{
loop1: sio_read( iPort,buf1,35);
for (i=0;i<30;i++)
{
if (buf1[i+0]==(char)0x1b && buf1[i+1]==(char) 0x05
&& buf1[i+2]==(char)0x00 && buf1[i+3]==(char)0x00
&& buf1[i+4]==(char)0x00)
{
for (j=0;j<35-i;j++)
buf2[j]=buf1[j+i];
sio_read(iPort,&buf2[35-i],40-(35-i));
bOrder=TRUE;
goto loop2;
break;
}
}
Sleep (50);
goto loop1;
}
loop2: if (buf2[7]==(char)0x24 && buf2[8]==(char) 0x01)
{
for (i=0;i<38;i++)
buf3[i]=(unsigned char) buf2[i];
iCode=0xffff;
for (i=0;i<38;i++)
iCode=CRC1(iCode,*(buf3+i));
}
else if (buf2[5]==0x05)
{
len=sio_read(iPort,buf1,28);
goto wait;
}
else
{
bOrder=FALSE;
sio_flush(iPort,0);
goto loop1;
}
if (*(buf2+38)==(char)(iCode&0x00ff) &&
*(buf2+39)==(char)(iCode>>8))
{
for (i=0;i<7;i++)
{
buf1[i*4]=buf2[i*4+9+3];
buf1[i*4+1]=buf2[i*4+9+2];
buf1[i*4+2]=buf2[i*4+9+1];
buf1[i*4+3]=buf2[i*4+9];
}
if(*(buf2+5)==01)
{
memcpy(a1,buf1,28);
a5[0]=a1[2];
}
if(*(buf2+5)==02)
{
memcpy(a2,buf1,28);
a5[1]=a2[2];
}
if(*(buf2+5)==03)
{
memcpy(a3,buf1,28);
a5[2]=a3[2];
}
if(*(buf2+5)==04)
{
memcpy(a4,buf1,28);
a5[3]=a4[2];
}
bOrder=TRUE;
}
else
{
bOrder=FALSE;
sio_flush(iPort,0);
}
Sleep(50);
}
return 0;
}
{
char buf2[100], buf1[100];
unsigned char buf3[50];
int len,len0;
int i,j,m;
unsigned int iCode;
static bool bOrder;
bOrder=FALSE;
m=0;
while (m_bSend)
{
wait: len0=sio_iqueue(iPort);
if (len0<100)
{
Sleep(50);
goto wait;
}
if (bOrder)
{
sio_read( iPort, buf1, 65);
for (i=0;i<40;i++)
buf2[i]=buf1[25+i];
}
else
{
loop1: sio_read( iPort,buf1,35);
for (i=0;i<30;i++)
{
if (buf1[i+0]==(char)0x1b && buf1[i+1]==(char) 0x05
&& buf1[i+2]==(char)0x00 && buf1[i+3]==(char)0x00
&& buf1[i+4]==(char)0x00)
{
for (j=0;j<35-i;j++)
buf2[j]=buf1[j+i];
sio_read(iPort,&buf2[35-i],40-(35-i));
bOrder=TRUE;
goto loop2;
break;
}
}
Sleep (50);
goto loop1;
}
loop2: if (buf2[7]==(char)0x24 && buf2[8]==(char) 0x01)
{
for (i=0;i<38;i++)
buf3[i]=(unsigned char) buf2[i];
iCode=0xffff;
for (i=0;i<38;i++)
iCode=CRC1(iCode,*(buf3+i));
}
else if (buf2[5]==0x05)
{
len=sio_read(iPort,buf1,28);
goto wait;
}
else
{
bOrder=FALSE;
sio_flush(iPort,0);
goto loop1;
}
if (*(buf2+38)==(char)(iCode&0x00ff) &&
*(buf2+39)==(char)(iCode>>8))
{
for (i=0;i<7;i++)
{
buf1[i*4]=buf2[i*4+9+3];
buf1[i*4+1]=buf2[i*4+9+2];
buf1[i*4+2]=buf2[i*4+9+1];
buf1[i*4+3]=buf2[i*4+9];
}
if(*(buf2+5)==01)
{
memcpy(a1,buf1,28);
a5[0]=a1[2];
}
if(*(buf2+5)==02)
{
memcpy(a2,buf1,28);
a5[1]=a2[2];
}
if(*(buf2+5)==03)
{
memcpy(a3,buf1,28);
a5[2]=a3[2];
}
if(*(buf2+5)==04)
{
memcpy(a4,buf1,28);
a5[3]=a4[2];
}
bOrder=TRUE;
}
else
{
bOrder=FALSE;
sio_flush(iPort,0);
}
Sleep(50);
}
return 0;
}