libusb / hidapi

A Simple cross-platform library for communicating with HID devices
https://libusb.info/hidapi/
Other
1.68k stars 398 forks source link

Doesnt work properly on windows #687

Closed pituluk closed 3 months ago

pituluk commented 3 months ago
  1. hid_enumerate doesnt find all devices properly I input VID and PID and it found only 2 out of 3 devices that I can find in dev manager, they differ by collection id
  2. hid_get_input_report doesnt work at all, error Get Input/Feature Report DeviceIoControl: (0x00000057) I dont know why it errors out

    std::string getHeadsetDeviceInfo()
    {
    struct hid_device_info* devices = NULL;
    while (devices == NULL)
    {
        devices = hid_enumerate(0x0951, 0x16ed);
    }
    auto iterable = devices;
    while (iterable->next)
    {
        std::wcout << iterable->manufacturer_string << L' ' << iterable->product_string << L' ' << iterable->usage << L' ' << iterable->path << L'\n';
        std::string path = iterable->path;
        if (path.find("Col03") != 0)
        {
            hid_free_enumeration(devices);
            return path;
        }
        iterable = iterable->next;
    }
    hid_free_enumeration(devices);
    return "";
    }
    int main()
    {
    std::string path = getHeadsetDeviceInfo();
    auto device = hid_open_path(path.c_str());
    if (device == NULL)
    {
      std::cout << "Device wrong\n";
      return 0;
    }
    std::vector<unsigned char> vec;
    vec.resize(2048);
    while (true)
    {
    
      int readBytes = hid_get_input_report(device, vec.data(), 2048);
      if (readBytes == 0)
      {
          Sleep(10);
          continue;
      }
      if (readBytes == -1)
      {
          auto err = hid_error(device);
          std::wcout << L"Error reading "<<err<<L'\n';
          break;
      }
      for (int i = 0; i < readBytes; i++)
      {
          printf("%02X ", vec[i]);
      }
      std::cout << '\n';
    }

    I know this code sucks btw I return when Col03 is found but even without that if branch it outputs only Col02 Col03 while in dev manager I can find a device with Col01 too

Youw commented 3 months ago

Doesnt work properly on windows

You've mentioned Windows, should I assume you've tried other platforms (Linux-libusb/Linux-hidraw/macOS) and it works fine?

it found only 2 out of 3 devices

while (iterable->next)
{
    // ...
    iterable = iterable->next;
}

Of course you missed one device. It is returned by hid_enumerate. You should re-vesiti how your while loop works with this implementation.

hid_get_input_report doesnt work at all... I dont know why it errors out

That I cannot know as well. Could be many reasons.


I suggest you first try hidapitester. If your device works with the tool - the problem is with your implementation, you may use hidapitester as a reference. If the device/API still doesn't work with the tool - first need to check device descriptor and see if it should work at all the way you're trying to.


I don't see any immediate issue with HIDAPI. This is an issue tracker, not a support forum. Closing this one for now.

If you find a specific issue with HIDAPI (specially if something works on one platform and doens't work on another, e.g. Windows vs Linux vs macOS) - feel free to re-open/open another one.