写入 USB HID 设备的程序会导致“冻结”当设备反复插入和移除时

发布于 2024-10-12 13:36:49 字数 664 浏览 3 评论 0原文

当我在低端计算机 (XP Pro SP3) 上拔出并重新插入自定义 HID 设备足够多次时,Windows 会停止识别新的 USB 连接并在任何 USB 端口(任何设备类别)上断开连接。我们打开驱动程序验证程序,并收到 0xC9 错误检查 (DRIVER_VERIFIER_IOMANAGER_VIOLATION),错误代码为 0x21D(IRP 调度处理程序在收到删除 IRP 后未正确从其下方的堆栈中分离)。引用的驱动程序文件是 HIDCORE.SYS。我们使用 Windows 内置的 HID 驱动程序。

仅当我们编写的实用程序正在运行并向设备发送一些命令时,才会出现此问题。当该实用程序运行时,我们可以在 USB“锁定”之前在任何地方连接和断开设备 3 到 30 次。所有连接的设备仍然可以工作,但不会识别新的连接/断开事件。它在低端机器上最容易重现,但偶尔会在中端 PC 上发生。我们发现,唯一的方法是重新启动,关闭我们的应用程序不会导致 USB 设备再次被识别。

我已确保在收到断开连接事件时关闭设备的所有文件句柄。

我没有使用 RegisterDeviceNotification,而是使用 WMI ManagementEventWatcher 来获取设备连接和断开连接时的事件。

我想知道如何避免这种“冻结”。我不确定我们的应用程序是否未正确与驱动程序断开连接,设备是否执行错误,或者 Window XP HID 驱动程序是否有问题。

When I unplug and replug a custom HID device enough times on a low-ish-end machine (XP Pro SP3), Windows stops recognizing new USB connects and disconnects on any USB port (any device class). We turned on the Driver Verifier, and got a 0xC9 bugcheck (DRIVER_VERIFIER_IOMANAGER_VIOLATION), with an error code of 0x21D (An IRP dispatch handler has not properly detached from the stack below it upon receiving a remove IRP). The driver file that was referenced is HIDCORE.SYS. We are using the HID driver built into Windows.

The problem only occurs when a utility we wrote is running that sends a few commands to the device. While this utility is running, we can connect and disconnect the device anywhere from 3 to 30 times before the USB "locks up". Any connected devices still work, but no new connect/disconnect events are recognized. It's most reproducible on lower-end machines, but will occasionally happen on a medium-end PC. The only way, that we have found, out of this is to reboot, closing our application does not cause USB devices to be recognized again.

I've made sure we're closing all our file handles to the device when we get a disconnect event.

I am not using RegisterDeviceNotification, rather I am using the WMI ManagementEventWatcher to get events when devices are connected and disconnected.

I would like to know how to avoid this "freeze". I am not sure if our application is not disconnecting from the driver properly, if the device is doing something wrong, or if there is something wrong the the Window XP HID driver.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文