Pages: [1]   Go Down
Author Topic: Uno and ReadFile not returning an error  (Read 857 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 - downloaded 8 times.)
* serialtest.cpp (4.55 KB - downloaded 13 times.)
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 197
Posts: 12739
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
    //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?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 197
Posts: 12739
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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.
Logged

Pages: [1]   Go Up
Jump to: