串口读取不到数据,求解, 谢谢各位大侠,急
网上的例子,就是读取不到数据 ,请高手指点,谢谢!!!!void CRS485CommDlg::OnReceive()
{
OVERLAPPED m_osRead;
memset(&m_osRead,0,sizeof(OVERLAPPED));
m_osRead.hEvent=CreateEvent(NULL,TRUE,FALSE,NULL);
COMSTAT ComStat;
DWORD dwErrorFlags;
char str[100];
memset(str,'\0',100);
DWORD dwBytesRead=100;//读取的字节数
BOOL bReadStat;
ClearCommError(hCom,&dwErrorFlags,&ComStat);
dwBytesRead = min(dwBytesRead, (DWORD)ComStat.cbInQue);
bReadStat = ReadFile(hCom,str,dwBytesRead,&dwBytesRead,&m_osRead);
if(!bReadStat)
{
if(GetLastError()==ERROR_IO_PENDING)
{
WaitForSingleObject(m_osRead.hEvent, 2000);
}
}
PurgeComm(hCom, PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR|PURGE_RXCLEAR);
m_disp = str;
UpdateData(FALSE);
}