if((dwCommStatus & EV_RXCHAR) == EV_RXCHAR)
{
if(ReadFile(handle,cGetByte, 151, &dwReadCount, NULL)!=0)
{ str = _T("");
CString tmp = _T("");
for(int i = 0; i < dwReadCount; i++)
{
tmp.Format("%02x ", cGetByte[i]);
str += tmp;   
}
// tmp.Format("%d",);
// AfxMessageBox(tmp);
// TRACE(str);
AfxMessageBox(str);
}
}
dwReadCount要不是14就是28,而正确来说我有151个字节,怎么解决啊?最好不要用到
Sleep(),

解决方案 »

  1.   

    DWORD dwRealReadCount = 0;
    while (true)
    {
    if(ReadFile(handle,cGetByte, 151, &dwReadCount, NULL)!=0)
    {                           dwRealReadCount += dwReadCount;
    str = _T("");
    CString tmp = _T("");
    for(int i = 0; i < dwReadCount; i++)
    {
    tmp.Format("%02x ", cGetByte[i]);
    str += tmp;   
    }
    // tmp.Format("%d",);
    // AfxMessageBox(tmp);
    // TRACE(str);
    AfxMessageBox(str);
    }
    if (dwRealReadCount >= 151)
    {
      break;
    }}