如何检测连接到系统的设备何时可供使用?
如果这与之前的问题类似,我很抱歉,但这是我刚刚注意到的。 我可以检测我的设备何时连接到系统(通过 USB)并正确捕获消息,但是如果我拔下并重新插入设备,尝试通过 CreateFile() 函数始终返回错误:ERROR_GEN_FAILURE 31 (0x1F)这意味着 -连接到系统的设备无法运行,但是,在收到 微软自己的定义是“设备或介质已插入并且现已推出”。我相信这里发生的情况是,该错误更多地与设备未准备好有关,即使它被报告为已准备好,因为如果我再次重新枚举系统上的设备列表,则该设备已准备好。还有其他人遇到过并解决了这个问题吗?或者我遗漏/忽略了什么?
I'm sorry if this is similar to an earlier question but this is something I just noticed.
I can detect when my device is attached to the system (via usb) and trap the message correctly however if I unplug and plug the device back, attempting to access the device via the CreateFile() function always returns an error: ERROR_GEN_FAILURE 31 (0x1F) which translates to -A device attached to the system is not functioning, this is however, attempted after recieving the DBT_DEVICEARRIVAL message which by microsoft's own definition says "A device or piece of media has been inserted and is now available". I believe what's going on here is that the error has more to do with the device not being ready even though it's reported as being ready because if I re-enumerate the list of devices on the system again, the device is ready. Has anyone else encountered and gotten past this problem? Or is there something I'm missing/overlooking?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,处理这个问题最简单的方法是通过 WMI。
请参阅此处: http://dotnetslackers.com/community/blogs/basharkokash/archive/2008/02/06/usb-port-insert-remove-detection-using-wmi.aspx
我在USB 驱动器检测过去了,它非常简单,回调使事情变得非常干净
The simplest way to deal with this, IMO, is through WMI.
See here: http://dotnetslackers.com/community/blogs/basharkokash/archive/2008/02/06/usb-port-insert-remove-detection-using-wmi.aspx
I have used WMI in the past for USB drive detection and it is dead simple and the callback makes things pretty clean