Problems with ClearCommError
-
Hi. I have developed an aplication that it read and write bytes through the serial ports. The program works fine, except for some PCs, (very few ones). While is reading the data, sometimes it ends the communication suddenly. I found that it happend because ClearCommError fails, I have the following code:
... // the following loop try to send a command and read the answer while( retry> 0 ) { // the problem is here, when that function fails if( !ClearCommError( idCommDev, &dwError,&comstatInfo )) { lResult = 116; dwLasError = GetLastError(); // I call GetLastError() but I get -1. ??????? return lResult; } if( !PurgeComm( idCommDev, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR )) { lResult = 115; return lResult; } // Send a command lResult = TXPacket(dataTX, 250); if( lResult!= 0 ) return lResult; // Read the answer lResult = RXPacket(dataRX, timeout); ....
This is my problem. In some PC, (I don't know why), the function ClearCommError() fail with no error code available with GetLastError(), so I can't figure out what is happened. Thank you.Demian. "I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone." -Bjarne Stroustrup, computer science professor, designer of C++ programming language (1950- )