谢谢:
void CView2::CtrlSer()
{
while(1){
BYTE str[17]={'@','0','0','W','R','0','2','0','0','0','0','1'};
Xor(str,11);
CString order;
for(int i=0;i<12;i++)
{
order+=str[i];
}
order+="*\r"; //形成完整的通讯协议命令字符串;
OVERLAPPED m_osWrite;
memset(&m_osWrite,0,sizeof(OVERLAPPED));
m_osWrite.hEvent=CreateEvent(NULL,TRUE,FALSE,NULL);
DWORD dwBytesWrite=20;
DWORD dwErrorBlags;
BOOL bWriteStat;
COMSTAT comstat;
ClearCommError(hCom,&dwErrorBlags,&comstat);
bWriteStat=WriteFile(hCom,order,strlen(order),&dwBytesWrite,&m_osWrite);
if(!bWriteStat)
{
if(GetLastError()==ERROR_IO_PENDING)
{
WaitForSingleObject(m_osWrite.hEvent,1000);
}
}
}
}
上面是我写的代码,请那位高手帮我看看有那里不对么?请大家指正!谢谢