郁闷,请问,我用串口通讯写的一程序,在用F9设置断点的情况,可以正常运行,可是把断点取点后,就像没有收到数据一样没有反应,是那里的 如题,谢谢!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 DWORD _stdcall TGGCommunication::CommThread(LPVOID pParam){ TGGCommunication *port = (TGGCommunication*)pParam; port->m_bThreadAlive = true; //DWORD BytesTransfered = 0; DWORD Event = 0; DWORD CommEvent = 0; DWORD dwError = 0; COMSTAT comstat; BOOL bResult = true; // Clear comm buffers at startup if (port->m_hComm) // check if the port is opened PurgeComm(port->m_hComm, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT); // begin forever loop. This loop will run as long as the thread is alive. for (;;) { bResult = WaitCommEvent(port->m_hComm, &Event, &port->m_ov); if (!bResult) { switch (dwError = GetLastError()) { case ERROR_IO_PENDING: { break; } case 87: { break; } default: { port->ProcessErrorMessage("WaitCommEvent()"); break; } } } else { bResult = ClearCommError(port->m_hComm, &dwError, &comstat); if (comstat.cbInQue == 0) continue; } // end if bResult Event = WaitForMultipleObjects(3, port->m_hEventArray, false, INFINITE); switch (Event) { case 0: { port->m_bThreadAlive = false; ExitThread(100); break; } case 1: // read event { GetCommMask(port->m_hComm, &CommEvent); if (CommEvent & EV_CTS) ::SendMessage(port->m_pOwner->Handle, WM_COMM_CTS_DETECTED, (WPARAM) 0, (LPARAM) port->m_nPortNr); if (CommEvent & EV_RXFLAG) ::SendMessage(port->m_pOwner->Handle, WM_COMM_RXFLAG_DETECTED, (WPARAM) 0, (LPARAM) port->m_nPortNr); if (CommEvent & EV_BREAK) ::SendMessage(port->m_pOwner->Handle, WM_COMM_BREAK_DETECTED, (WPARAM) 0, (LPARAM) port->m_nPortNr); if (CommEvent & EV_ERR) ::SendMessage(port->m_pOwner->Handle, WM_COMM_ERR_DETECTED, (WPARAM) 0, (LPARAM) port->m_nPortNr); if (CommEvent & EV_RING) ::SendMessage(port->m_pOwner->Handle, WM_COMM_RING_DETECTED, (WPARAM) 0, (LPARAM) port->m_nPortNr); if (CommEvent & EV_RXCHAR) ReceiveChar(port, comstat); break; } case 2: { WriteChar(port); break; } }// end switch }// close forever loop } delete port;} 可以在收之前sleep一下。因为你去收的时候设备未必准备好你去读数据了。 Sleep()因为你断点调试时相当于作了Sleep()操作。 问下raw socket能统计到各个进程的流量嘛? 用WebBrowser控件打开PowerPoint后, 怎么让它翻页(自己设定的,比如一秒或多少时间一页) 寻找伙伴 如何控制窗口大小 列表框问题 请问再vc中用debug的watch怎样看一个静态变量的值?? 自绘菜单的问题 大家推荐几款好用的安装程序制作软件~ 关于线程的内存回收 请教一个关于C++术语译法的问题! 脚本语言lua支持中文的脚本吗? 如何用程序控制改变中文输入法中的顺序?
{
TGGCommunication *port = (TGGCommunication*)pParam;
port->m_bThreadAlive = true;
//DWORD BytesTransfered = 0;
DWORD Event = 0;
DWORD CommEvent = 0;
DWORD dwError = 0;
COMSTAT comstat;
BOOL bResult = true; // Clear comm buffers at startup
if (port->m_hComm) // check if the port is opened
PurgeComm(port->m_hComm, PURGE_RXCLEAR | PURGE_TXCLEAR | PURGE_RXABORT | PURGE_TXABORT); // begin forever loop. This loop will run as long as the thread is alive.
for (;;)
{
bResult = WaitCommEvent(port->m_hComm, &Event, &port->m_ov);
if (!bResult)
{
switch (dwError = GetLastError())
{
case ERROR_IO_PENDING:
{
break;
}
case 87:
{
break;
}
default:
{
port->ProcessErrorMessage("WaitCommEvent()");
break;
}
}
}
else
{
bResult = ClearCommError(port->m_hComm, &dwError, &comstat);
if (comstat.cbInQue == 0)
continue;
} // end if bResult
Event = WaitForMultipleObjects(3, port->m_hEventArray, false, INFINITE);
switch (Event)
{
case 0:
{
port->m_bThreadAlive = false;
ExitThread(100);
break;
}
case 1: // read event
{
GetCommMask(port->m_hComm, &CommEvent);
if (CommEvent & EV_CTS)
::SendMessage(port->m_pOwner->Handle, WM_COMM_CTS_DETECTED, (WPARAM) 0, (LPARAM) port->m_nPortNr);
if (CommEvent & EV_RXFLAG)
::SendMessage(port->m_pOwner->Handle, WM_COMM_RXFLAG_DETECTED, (WPARAM) 0, (LPARAM) port->m_nPortNr);
if (CommEvent & EV_BREAK)
::SendMessage(port->m_pOwner->Handle, WM_COMM_BREAK_DETECTED, (WPARAM) 0, (LPARAM) port->m_nPortNr);
if (CommEvent & EV_ERR)
::SendMessage(port->m_pOwner->Handle, WM_COMM_ERR_DETECTED, (WPARAM) 0, (LPARAM) port->m_nPortNr);
if (CommEvent & EV_RING)
::SendMessage(port->m_pOwner->Handle, WM_COMM_RING_DETECTED, (WPARAM) 0, (LPARAM) port->m_nPortNr);
if (CommEvent & EV_RXCHAR)
ReceiveChar(port, comstat);
break;
}
case 2:
{
WriteChar(port);
break;
}
}// end switch
}// close forever loop
}
delete port;
}
因为你去收的时候设备未必准备好你去读数据了。
因为你断点调试时相当于作了Sleep()操作。