亲爱的同学编码,
我面对这个问题,我的程序。该方案是与另一台机器,这是1Hz时输出串行数据接口。我的程序是MFC的基于一个cpropertypage和处理数据,我已经定义1线程(pRecvDataThread)来处理串行端口的缓冲区中的数据的读取,并显示在我的名单控制在主线程它。
我已经分开的GUI的东西,如清单控制等处理的线程在一些教程的建议。但是我的GUI仍然是难以响应。继承人的代码段,没有人知道什么错吗?
// on serial data arrival
LRESULT MyApp::OnDataArrived(WPARAM wParam,LPARAM lParam)
{
Sleep(40);
const CSerialMFC::EEvent eEvent = CSerialMFC::EEvent(LOWORD(wParam));
const CSerialMFC::EEvent eError = CSerialMFC::EEvent(HIWORD(wParam));
switch(eEvent)
{
case CSerialMFC::EEventRecv:
pRecvDataThread = AfxBeginThread(MyRecvThread, LPVOID(this), THREAD_PRIORITY_NORMAL);
break;
}
return 0;
}
// my thread proc
UINT MyRecvThread(LPVOID pParam)
{
MyApp *pTab = (MyApp*)pParam;
WaitForSingleObject(pTab ->MutexRecv, INFINITE);
DWORD dwBytesRead = 0;
byte abBuffer[512];
int errorInt = pTab->serialMFC.Read(abBuffer, sizeof(abBuffer), &dwBytesRead, 0, INFINITE);
if(errorInt != ERROR_SUCCESS)
{
AfxMessageBox(_T("ERROR in reading serial port"));
return 0;
}
char szTimestamp[128];
SYSTEMTIME st;
//GetSystemTime(&st);
GetLocalTime(&st);
sprintf_s(szTimestamp, 128, "%02d:%02d:%02d:%03d", st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
pTab->ReadData(abBuffer, szTimestamp, numBytesRead);
ReleaseMutex(MyApp->MutexRecv);
return 0;
}
void MyApp::ReadData(byte bytesRead [], char* timestamp, int bytesread)
{
// display the bytes in list control
}