Author Topic: Example winusb_cs  (Read 15440 times)

mikeindevon

  • Member
  • ***
  • Posts: 4
Example winusb_cs
« on: May 05, 2020, 12:53:18 pm »
I am trying to read from a device already installed on my machine and using the winusb.sys driver.  I have downloaded and built Jan's example application.  Where do I insert the GUID, VID and PID for the device into your code?  Is there anythingelse that I need to do to get the demo to talk to the device?

I have built an application using the winusb template from Visual Studio 2019 Pro, but for some reason the Device Manager wouldn't update the generated driver MyDriver.inf.  (This maybe a bug relating to driver certificate).  I don't fully understand why I need a new .inf file as the winusb.sys driver is already installed and I just want to talk to it.  Why isn't it possible to query the existing driver directly by giving it the GUID, VID and PID?  Any help would be appreciated as this is driving me nuts.

Michael

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Example winusb_cs
« Reply #1 on: May 05, 2020, 03:25:25 pm »
Look for this in frmMain_cs:

   // *************************************************************************************
      // Device-specific values. Edit to match your device.

      // If using the sytem-provided winusb.inf, this GUID must match the GUID in the device's
      // Microsoft OS 1.0 extended properties OS feature descriptor or
      // Microsoft OS 2.0 registry property feature descriptor.
      // If using a vendor-provided INF file, this GUID must match the GUID in the INF file.
      // The GUID should be unique to your device (and other devices that communicate in the same way).
      // To create a GUID in Visual Studio, click Tools > Create GUID.

      //private const String DeviceInterfaceGuid = "{f99baaba-f033-483d-afb2-a6e4f3ae6310}";
      private const String DeviceInterfaceGuid = "{ecceff35-146c-4ff3-acd9-8f992d09acdd}";

      // WMI functions use these values to detect device arrival and removal and get device properties.
      // Edit to match the values, expressed as hexadecimal numbers, in your device's device descriptor:

      private const String VendorID = "0925";
      private const String ProductID = "150C";

      // *************************************************************************************

mikeindevon

  • Member
  • ***
  • Posts: 4
Re: Example winusb_cs
« Reply #2 on: May 06, 2020, 04:25:52 am »
Thank you so much for that.  The demo is now talking to my device.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Example winusb_cs
« Reply #3 on: May 06, 2020, 12:49:14 pm »
Happy to hear it!

mikeindevon

  • Member
  • ***
  • Posts: 4
Re: Example winusb_cs
« Reply #4 on: May 09, 2020, 10:02:27 am »
I have followed through the example in great detail with the debugger in Visual Studio 2019 Pro and the upshot is that the device isn't found by the FindDeviceFromGuid() method although I have checked the GUID a thousand times.  However, the device is found by the WMI method, the properties are listed, and I can replicate all that in my own C++ code.  From this follows that the _deviceReady flag is never set TRUE and reads and writes are skipped in the code.

The device is a simple rotary knob with push button.  (WinUsb Device,  "88bae032-5a81-49f0-bc3d-a4ff138216d6").  It shows up in Device Manager as Type: Universal Serial Bus Devices. Your example code successfully copes with the device being unplugged and then plugged in again.  I haven't installed an additional .INF file.

I should be very grateful for any pointers on the way forward to get data out of this thing.

Michael

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Example winusb_cs
« Reply #5 on: May 09, 2020, 02:44:22 pm »
SetupDiEnumDeviceInterfaces fails to find a match?

The GUID looks correct when it's passed to SetupDiEnumDeviceInterfaces? (Use a breakpoint to view it)

mikeindevon

  • Member
  • ***
  • Posts: 4
Re: Example winusb_cs
« Reply #6 on: May 09, 2020, 04:26:29 pm »
Hi,
Yes, it fails to find the match.  I had already checked the params passed to that call and it all looked ok.  The first attached .jpg shows the debugger screen at the call and the Device Manager data.  The call returns success = false. The second shows the Watch window immediately prior to the call.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Example winusb_cs
« Reply #7 on: May 11, 2020, 11:05:58 am »
// If using the sytem-provided winusb.inf, this GUID must match the GUID in the device's
// Microsoft OS 1.0 extended properties OS feature descriptor or
// Microsoft OS 2.0 registry property feature descriptor.

Suggest using a protocol analyzer or other debugging tool to verify that the MS OS descriptor is transferring correctly during enumeration.

Renate

  • Frequent Contributor
  • ****
  • Posts: 97
Re: Example winusb_cs
« Reply #8 on: May 28, 2020, 10:16:10 am »
Your problem is that what is shown under Device Manager as "Class GUID" is not what you want.
{88bae032-5a81-49f0-bc3d-a4ff138216d6} is (generic) USB device.
The "Class GUID" is responsible for associating the pretty icon with the device.
As a matter of fact, what you want is not shown in Device Manager.
Handy, eh?

What you want is the GUID for the DEVINTERFACE.
It's probably {f72fe0d4-cbcb-407d-8814-9ed673d0dd6b} for WinUSB

You can find that in the INF file if you know which one it is using.
Code: [Select]
[Dev_AddReg]
HKR,,DeviceInterfaceGUIDs,0x10000,"{f72fe0d4-cbcb-407d-8814-9ed673d0dd6b}"

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Example winusb_cs
« Reply #9 on: May 28, 2020, 11:18:56 am »
Thank you, Renate!