如果需要多次使用ReadFile and WriteFile时,应该考虑没有数据读时的情况,如果没有数据读的话,那么你的程序在什么 什么呢?for ( ; ; ) { if (WaitCommEvent(hComm, &dwCommEvent, NULL)) { do { if (ReadFile(hComm, &chRead, 1, &dwRead, NULL)) // A byte has been read; process it. else // An error occurred in the ReadFile call. break; } while (dwRead); } else // Error in WaitCommEvent break; }这段代码是MSDN上的,根据需要在WaitCommEvent中加入超时设置
if (WaitCommEvent(hComm, &dwCommEvent, NULL)) {
do {
if (ReadFile(hComm, &chRead, 1, &dwRead, NULL))
// A byte has been read; process it.
else
// An error occurred in the ReadFile call.
break;
} while (dwRead);
}
else
// Error in WaitCommEvent
break;
}这段代码是MSDN上的,根据需要在WaitCommEvent中加入超时设置
你在vb中应该判断writefile是否成功,然后增加延时,在readfile