PORTS Forum
Ports and Interfaces => USB => Topic started by: moelski 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:
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
-
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.
-
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.
-
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.