I'm afraid I don't have many insights. Using overlapped IO may solve your problem of not knowing if an error occurred or not, but I don't think it will solve your general problem. One thing that might be worth looking at are "device notifications", which may be able to inform you of the removal - see win32\Demos\win32gui_devicenotify.py in build 211 for an example (I think that only will see mass-storage devices, but if you dig around MSDN you may have luck)
Cheers, Mark > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:python-win32- > [EMAIL PROTECTED] On Behalf Of Ron Jackson > Sent: Tuesday, 3 June 2008 8:30 AM > To: python-win32@python.org > Subject: [python-win32] USB CDC-class support with win32file, exception > processing issues > > When USB communication device class devices are installed in Windows > they appear as COMxxx ports, just like legacy serial ports. They are > different in that many RS-232 device parameters don't apply (such as > baud rate, handshaking, etc). Also, since they are USB devices they > may be suspended while remaining connected (as when the computer goes > into sleep mode), or may be unplugged at any time. > > I am creating a simple Python communications library to support > USB-CDC devices, ignoring the unused legacy features but adding > suspend and disconnect support. I have found some problems with > exception processing that is making this problematic. > > win32file.WriteFile works well. If the device is suspended I get > pywintypes.error (31, 'WriteFile', 'A device attached to the system is > not functioning.'). If the device is unplugged I get pywintypes.error > (1167, 'WriteFile', 'The device is not connected.'). > > I can find out if there are any characters in the input buffer using > win32file.ClearCommError. Its exception reporting half-way works. If > the device is suspended I get pywintypes.error (31, 'ClearCommError', > 'A device attached to the system is not functioning.'). But if the > device is unplugged I get no error reported at all. > > win32file.ReadFile provides neither of these errors. Either suspended > or unplugged just causes ReadFile to hang. I can get ReadFile to > return if I set a timeout, but no error is reported so I don't know if > it returned because the device hasn't sent the data yet, or because > the device is suspended or disconnected. > > Is there some way to get ReadFile to report errors 31 and 1167 like > WriteFile does? Or is there some other way to determine port status as > "attached but not functioning" or "not connected"? > > Thanks for the help! > > -- Ron > _______________________________________________ > python-win32 mailing list > python-win32@python.org > http://mail.python.org/mailman/listinfo/python-win32 _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32