I have a C# application interfacing to a USB barcode scanner. Everything works fine until Windows suspends the USB bus. Turning off "USB Selective Suspend" in the power settings is not an option. I need to detect when the device (or the usb bus) gets suspended.
I can detect when a USB device is connected or disconnected by overriding WndProc in a NativeWindow instance.
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_DEVICECHANGE: // (0x0219)
Console.WriteLine("Device presence Changed");
switch (m.WParam.ToInt32())
{
case Win32Usb.DEVICE_ARRIVAL: // inserted (0x8000)
Console.WriteLine("Device Inserted");
break;
case Win32Usb.DEVICE_REMOVECOMPLETE: // removed (0x8004)
Console.WriteLine("Device Removed");
break;
}
break;
}
base.WndProc(ref m);
}
But it does not tell me when a USB device gets suspended by Windows.
Anyone know the m.Msg or m.WParam that can tell me when a USB device goes to sleep (or wakes up)?
I know there are lots of USB libraries on nuget and most of them can tell you when a device is inserted/removed, but I can't find any to detect "USB Selective Suspend". I'm open to using 3rd party library if you know of one that can solve my problem.