Go Down

Topic: Uno and ReadFile not returning an error (Read 907 times) previous topic - next topic

bnicholson

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?


Coding Badly

Code: [Select]
    //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?

bnicholson

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.


Coding Badly


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.

Go Up