Author Topic: Win 8.1 - EnhancedPowerManagement Problems with HID  (Read 7879 times)

moelski

  • Member
  • ***
  • Posts: 12
Win 8.1 - EnhancedPowerManagement Problems with HID
« on: February 24, 2014, 09:22:31 am »
Hi !

I have some code to communicate with HID devices. This works very well on Windows until 8.0. Now there is 8.1 and I git problems.

If I try to read the ManufacturerString I get a windows Error 31 - A device attached to the system is not functioning.
Here is some code I use:
Code: [Select]
            DsHidApi.HIDD_ATTRIBUTES DeviceAttributes = new DsHidApi.HIDD_ATTRIBUTES();
            Boolean success = false;
            IntPtr preparsedData = new IntPtr();

            DeviceAttributes.Size = Marshal.SizeOf(DeviceAttributes);

             // open a read/write handle to our device using the DevicePath returned
            SafeHandle handle = DsKernel.CreateFile(
                this.DevicePath,
                FileAccess.ReadWrite,
                FileShare.ReadWrite,
                IntPtr.Zero,
                FileMode.Open,
                DsKernel.FileAttributes.Overlapped,
                IntPtr.Zero);

            success = DsHidApi.HidD_GetAttributes(handle.DangerousGetHandle(), ref DeviceAttributes);

            if (success)
            {
               // this.Accessible = true;

                this.Vid = DeviceAttributes.VendorID.ToString("X4");
                this.Pid = DeviceAttributes.ProductID.ToString("X4");
                this.Version = DeviceAttributes.VersionNumber;
                Debug.WriteLine("OK : " + this.DevicePath);

                success = DsHidApi.HidD_GetPreparsedData(handle.DangerousGetHandle(), ref preparsedData);
               
                DsHidApi.HIDP_CAPS Capabilities = new DsHidApi.HIDP_CAPS();
                Int32 result = 0;
                result = DsHidApi.HidP_GetCaps(preparsedData, ref Capabilities);

                int bufferLength = 126;
                byte[] buffer = new byte[bufferLength];

               ############## Thread.sleep(200);

                // Bei Api Call Problemem mit DsLog.ResultOfApiCall("HidD_GetManufacturerString"); abfragen
                if (DsHidApi.HidD_GetManufacturerString(handle.DangerousGetHandle(), buffer, bufferLength))
                {
                    this.Manufacturer = Encoding.Unicode.GetString(buffer).Replace("\0", string.Empty);
                }

If I place a Thread.sleep(200); before GetManufacturerString all works fine otherwise I get the error 31.

If I switch off the EnhancedPowerManagementEnabled to 0 it works fine again for the port:
http://blogs.msdn.com/b/usbcoreblog/archive/2013/11/08/help-after-installing-windows-8-1-my-usb-device-doesn-t-charge-or-it-disconnects-and-reconnects-frequently.aspx

So is there any HID command to wake up the device? I canīt beleave that the sleep is a good solution for that  ::)

Hope an any help.

Dominik

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Win 8.1 - EnhancedPowerManagement Problems with HID
« Reply #1 on: February 24, 2014, 10:25:02 am »
It sounds like a malfunctioning device that you will need to work around either with sleep (can't explain why that works!) or by disabling enhanced power management.

moelski

  • Member
  • ***
  • Posts: 12
Re: Win 8.1 - EnhancedPowerManagement Problems with HID
« Reply #2 on: February 24, 2014, 03:02:41 pm »
Hi !

No the device works perfect. And there are many people which report problems with Windows 8.1 and USB HID.

So there must be any trick. 

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Win 8.1 - EnhancedPowerManagement Problems with HID
« Reply #3 on: February 25, 2014, 09:21:52 am »
Perhaps the device works perfect except for responding to a request for a Manufacturer string under Windows 8.1 with EnhancedPowerManagementEnabled enabled...

If you can't change the device firmware or driver, you need to find a workaround in the host computer, as the Microsoft article suggests.