|
@@ -454,18 +454,28 @@ DWORD CSynSerial::ThreadWatch(LPVOID lpVoid)
|
|
|
memset(szValue, 0, 1024);
|
|
|
if ( (dwRealRead = pthat->ReadComm((BYTE*)szValue, 1024)) > 0) {
|
|
|
AutoThreadSection aSection(&s_csClearBuffer);
|
|
|
+
|
|
|
+#ifdef _DEBUG
|
|
|
OutputDebugString(_T("内容:"));
|
|
|
OutputDebugString(szValue);
|
|
|
OutputDebugString(_T("\n"));
|
|
|
+#endif
|
|
|
|
|
|
#if 1
|
|
|
- pthat->SwapBuffers(szValue, dwRealRead);
|
|
|
+ if ( pthat->m_strbuffer.length() > BUFFER_LEN * 10 ) {
|
|
|
+ int nIndex = 0;
|
|
|
+ pthat->m_strbuffer = pthat->m_strbuffer.substr(BUFFER_LEN * 9);
|
|
|
+ if ( (nIndex = pthat->m_strbuffer.find_first_of('\r')) != std::string::npos )
|
|
|
+ pthat->m_strbuffer = pthat->m_strbuffer.substr(nIndex+1);
|
|
|
+ }
|
|
|
+
|
|
|
+ pthat->m_strbuffer.append(szValue, dwRealRead);
|
|
|
#else // 这里如果不及时清除,内存越来越大;
|
|
|
pthat->m_strbuffer.append(szValue, dwRealRead);
|
|
|
#endif
|
|
|
}
|
|
|
|
|
|
- } while ( WaitForSingleObject(pthat->m_hEvent, 50) == WAIT_TIMEOUT );
|
|
|
+ } while ( WaitForSingleObject(pthat->m_hEvent, 30) == WAIT_TIMEOUT );
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
printf("线程结束\n");
|
|
@@ -477,13 +487,13 @@ DWORD CSynSerial::ThreadWatch(LPVOID lpVoid)
|
|
|
bool CSynSerial::FindWord(std::string strWord, int nWatchTime )
|
|
|
{
|
|
|
bool found = false;
|
|
|
- int nSize = nWatchTime/50;
|
|
|
+ int nSize = nWatchTime/30;
|
|
|
for ( int i = 0; i < nSize; i++ ) {
|
|
|
if ( m_strbuffer.find(strWord) != std::string::npos ) {
|
|
|
found = true;
|
|
|
break;
|
|
|
}
|
|
|
- Sleep(10);
|
|
|
+ Sleep(30);
|
|
|
}
|
|
|
|
|
|
return found;
|