问题
When looking for a WM_DEVICECHANGE
message for a BLE HID device via WndProc
the arrival and removal messages sometimes occur 1-4 times without any actual removal or turning off of the device. On arrival, I setup communication and on removal I end communication. However, I wanted to see if communication could still occur if I ignored subsequent removal messages and kept reading from the device via ReadFile
.
What I found is that I would get a read failure if another removal message came in. Basically, what happens is it goes through the arrival and removal sequence until the device seems to be setup properly and then on the final arrival message the device communication is setup. At that point the communication won't be interrupted and can read data properly.
I have no problems with messages like this over USB HID. I'm not sure if this is a lower level issue with the device I'm using that could be corrected. If the device could reconnect on the first attempt than it would save time vs waiting for 2-4 arrival/removals.
If this is a common occurrence with BLE HID devices I'll take any answer that explains why multiple arrivals and removals occur.
Another bit of info is that I'm seeing this also occur in a C# app that uses the .NET wrapper for the C++ code. In SimpleHIDWrite https://github.com/Robmaister/SimplerHidWrite the app also gets the device arrival and removal multiple times for the BLE device. The only difference between my application device event system and SimpleHIDWrite is I'm using native code. So the issue might not be code related and be more about the device.
来源:https://stackoverflow.com/questions/56655681/why-are-there-multiple-dbt-deviceremovecomplete-messages-for-a-ble-hid-device