关于串口通讯的问题
本人在项目中用了现有的写好的CSerialPort类,没有利用MSCOMM控件。现在遇到的问题是:当多的串口同时接收数据时,若想关闭某一串口:
port.StopMonitoring();
程序就会死掉,单步跟进去发现,StopMonitoring()这个函数中有问题:
BOOL CSerialPort::StopMonitoring()
{
if(m_bThreadAlive)
{
do
{
SetEvent(m_hShutdownEvent);
}
while (m_bThreadAlive);
TRACE("Thread ended\n");
}
if (m_hComm != NULL)
{
CloseHandle(m_hComm);
m_hComm = NULL;
}
return TRUE;
}
程序一直出不了do...while...这个循环,也就是说m_bThreadAlive一直不能被置为FALSE,请做过串口项目的高手指教,谢了~~!!!