|
需要接收十六进制的数据(如:8101020304FF),收到并判断命令是否正确,但是小弟不知道如何判断,请各位大侠指教。
接受函数如下:
DWORD CPSerialPort::ReadPort(char *data,int length)
{
BOOL fReadState;
DWORD dwLength,dwBytesRead;
int TimeOutCount;
dwBytesRead=0;
TimeOutCount=0;
while(m_hComm!=INVALID_HANDLE_VALUE)
{
char* buf=new char[length];
fReadState=ReadFile(m_hComm,data,length,&dwLength,NULL);
if(!fReadState)
{
break;
}
else
{
dwBytesRead+=dwLength;
data+=dwLength;
}
if(dwBytesRead==(DWORD)length)
{
break;
}
if(dwLength!=0)
{
TimeOutCount=0;
}
else
{
TimeOutCount++;
Sleep(5);
}
if(TimeOutCount==5)
{
break;
}
}
return dwBytesRead;
}
|
|