-1

In my project (C#, WPF application) I have device that appears as VCP. I need connect to it. I am detecting serial port using WMI and filter by VID and PID. It makes job done in 90%. Device manufacturer uses same VID/PID pair for all devices. Accurate model is in USB descriptor (Device Decsriptor part, property iProduct). I can't find this anywhere exploring WMI.

How can I get to USB decriptor with .NET? In C# read USB Descriptor answers suggest to use WMI. In WMI device description is not USB descriptor. I don't need to list connected USB devices but to read specific data from USB device descriptor.

Luk3
  • 21
  • 3
  • 1
    Possible duplicate of [C# read USB Descriptor](https://stackoverflow.com/questions/14518778/c-sharp-read-usb-descriptor) – jegtugado Sep 07 '18 at 07:16
  • 1
    I saw it. I have used search function before asking. It doesn't answer my question. I am new contributor but not new reader of stackoverflow. – Luk3 Sep 07 '18 at 07:46
  • The WMI provider has many other fields than what the accepted answer shows, did you read through the [2nd answer](https://stackoverflow.com/a/37604994/80274) and try some of it's suggestions? – Scott Chamberlain Sep 07 '18 at 08:06
  • Yes. I need exacly iProduct field from Device Descriptor. Unfortunately, this is just one property that distinguishes two devices from that manufacturer. https://www.beyondlogic.org/usbnutshell/usb5.shtml#DeviceDescriptors I'am afraid that only SetupAPI can help... – Luk3 Sep 07 '18 at 08:33

1 Answers1

1

Very helpful article https://lihashgnis.blogspot.com/2018/07/getting-descriptors-from-usb-device.html I have just added some code to get String Descriptor:

    USB_STRING_DESCRIPTOR* stringDescriptor = nullptr;
    int sBufferSize = sizeof(USB_DESCRIPTOR_REQUEST) + MAXIMUM_USB_STRING_LENGTH;
    BYTE *sBuffer = new BYTE[sBufferSize];
    memset(sBuffer, 0, sBufferSize);

    requestPacket = (USB_DESCRIPTOR_REQUEST*)sBuffer;
    stringDescriptor = (USB_STRING_DESCRIPTOR*)((BYTE*)sBuffer + sizeof(USB_DESCRIPTOR_REQUEST));

    requestPacket->SetupPacket.bmRequest = 0x80;
    requestPacket->SetupPacket.bRequest = USB_REQUEST_GET_DESCRIPTOR;
    requestPacket->ConnectionIndex = usbPortNumber;
    requestPacket->SetupPacket.wValue = (USB_STRING_DESCRIPTOR_TYPE << 8); // String Descriptior 0
    requestPacket->SetupPacket.wLength = MAXIMUM_USB_STRING_LENGTH;

    err = DeviceIoControl(hUsbHub, IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, sBuffer, sBufferSize, sBuffer, sBufferSize, &bytesReturned, nullptr);

    // Now get iProduct string in language at zero index
    requestPacket->SetupPacket.wValue = (USB_STRING_DESCRIPTOR_TYPE << 8) | deviceDescriptor->iProduct;
    requestPacket->SetupPacket.wIndex = (USHORT)stringDescriptor->bString[0];

    err = DeviceIoControl(hUsbHub, IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, sBuffer, sBufferSize, sBuffer, sBufferSize, &bytesReturned, nullptr);

    std::wcout << stringDescriptor->bString
Luk3
  • 21
  • 3