|
********************************************************************************************/
DWORD CProjectDlg::CommRecvTread(LPVOID lparam)
{
DWORD dwLength;
BYTE *recvBuf = new BYTE[16];
CProjectDlg *pDlg = (CProjectDlg*)lparam;
while(TRUE)
{ /* 等待线程退出事件 */
if (WaitForSingleObject(pDlg->m_ExitThreadEvent, 0) == WAIT_OBJECT_0)
break;
if (pDlg->m_hComm != INVALID_HANDLE_VALUE)
{ /* 从串口读取数据 */
BOOL fReadState = ReadFile(pDlg->m_hComm, recvBuf, 16, &dwLength, NULL);
if(!fReadState)
{
//MessageBox(_T("无法从串口读取数据!"));
}
else
{
if(dwLength != 0)
{
OnCommRecv(pDlg, recvBuf,pDlg->RecvCOMData, 16); /* 接收成功调用回调函数 */
PurgeComm(pDlg->m_hComm, PURGE_RXCLEAR | PURGE_TXCLEAR );
SetCommMask (pDlg->m_hComm, EV_RXCHAR | EV_CTS | EV_DSR );
}
}
}
}
// SetEvent(pDlg->m_ExitThreadEvent);/////对事件对象标识
delete[] recvBuf;
return 0;
}
我写的接收函数
参考一下 |
|