Windows: Errors 31 or 7 after some time of successful operation

We’re using two BlinkStick Flex’s on each computer in a packaging environment to indicate which items to pick per customer package. We’re using SetupDiEnumDeviceInterfaces and HidD_SetFeature ourselves to connect to the devices and this works great. Sadly now and again this fails, and GetLastError returns 31 or 7, also after repeated retries. Disconnecting the USB devices (or the USB hub they’re on) helps, but we can’t depend on this method for daily operation.

We’ve tried using blinkstick.exe as a proof-of-concept, but this also isn’t usable in normal operation as it performs much too slowly. Also when the BlinkStick Flex’s are failing, blinkstick.exe responds with “Device opened successfully.” but with nothing where the serial number is supposed to be.

Would you have idea’s of things we could try? Of would you like to have a demo application that mimics typical operation and the commands we send to the devices to have a try yourself?

We’ve also been investigating for a way to reproduce this, but haven’t found anything yet. There’s a very slim chance that the barcode scanner, connected over USB also, may be involved, but it’s not straightforward to prove this.

I tried a few things on a system where it failed again today, and ‘uninstalled’ from the device manager, and then ‘scan for hardware changes’. The item reappears, but if I remove “HID-compliant vendor-defined device” blinkstick.exe still answers “Device opened successfully.” without serial number, if I remove the parent “USB Input Device” (devices are shown ‘by connection’ here:)
blinkstick.exe does get the serrial number, but after a few minutes the BlinkStick Flex starts to fail again, throwing 31 errors “A device attached to the system is not functioning”

I’ve been able to avoid some of the errors 31 by spacing the HidD_SetFeature calls in time by keeping at least 50 milliseconds between them, but I’m not sure if this will prevent the system of going into this error-condition where all calls get error 31.

It doesn’t. We’ve also have gotten a few times that the mouse cursor started to move, without mouse input. Could this be a problem with Windows’ hid.dll?