UINT ReadCountOrder(LPVOID pParam)
{
CView2* pV2=(CView2*)pParam;
CString order;
BYTE str[17]={'@','0','0','R','C','0','0','0','0','0','0','0','1',0,0,'*',13};
pV2->Xor(str,12);
for(int i=0;i<17;i++)
{
order+=str[i];
}
OVERLAPPED m_osWrite;
memset(&m_osWrite,0,sizeof(OVERLAPPED));
m_osWrite.hEvent=CreateEvent(NULL,TRUE,FALSE,NULL);
DWORD dwBytesWrite=17;
DWORD dwErrorFlags;
BOOL bReadOrderStat;
COMSTAT ComStat;
while(1)
{
TRACE(order);
ClearCommError(pV2->hCom1,&dwErrorFlags,&ComStat);
PurgeComm(pV2->hCom1, PURGE_TXABORT|PURGE_RXABORT|PURGE_TXCLEAR|PURGE_RXCLEAR);
bReadOrderStat=WriteFile(pV2->hCom1,order,dwBytesWrite,&dwBytesWrite,&m_osWrite);
if(!bReadOrderStat)
{
if(GetLastError()==ERROR_IO_PENDING)
{
WaitForSingleObject(m_osWrite.hEvent,1000);
}
}
else
{
pV2->ReadCountData();
}
dwErrorFlags=GetLastError();
Sleep(500);
}
return 0;
}
这是我写的一个读计数器的线程,可是我总是写串口失败阿,请问哪位高手知道那里出错了