Uno and ReadFile not returning an error

I developed a program on Win7 that reads data from the Arduino USB/COM port using ReadFile.

With all the non UNO Arduino’s whenever the USB is disconnected from the Win7 PC ReadFile returns an error and I then close the handle. The Win7 C++ code then starts a for loop looking for the Arduino USB/COM port to be plugged back into the machine.

Unfortunately, with the UNO ReadFile never returns an error if the UNO USB is unplugged from the computer. So my program is now stuck in a loop trying to read data from a port that isn’t there any more.

ReadFile() returns ERROR_OPERATION_ABORTED when the USB is unplugged on any non UNO Arduino.
ReadFile() never returns ever when a UNO is unplugged.

Any ideas?

Serial.h (1.34 KB)

serialtest.cpp (4.55 KB)

    //Use the ClearCommError function to get status info on the Serial port
    ClearCommError(this->hSerial, &this->errors, &this->status);

The return value is? You did not check the return value because?

I modified the routine to check the ClearCommError() function. Success was returned.

No difference at all in the ReadFile(). It never returns if you unplug the UNO during the read.

I have reproduced the problem (on Vista). Unfortunately, you have crossed paths with a bug in the kernel driver; Microsoft's kernel driver. Apparently the work-around is RegisterDeviceNotification.