Ahmad45123
Ahmad45123

Reputation: 472

UsbDevice.FromIdAsync returns null

I have this code:

private async void OnDeviceAdded(DeviceWatcher watcher, DeviceInformation deviceInformation)
    {
        if (deviceInformation.Name.StartsWith("ClearShot") && deviceInformation.IsEnabled)
        {

            targetDevice = await UsbDevice.FromIdAsync(deviceInformation.Id);
            OnConnected(EventArgs.Empty);

        }

    }

This is actually an event that is called from a DeviceWatcher The problem is that targetDevice is always null.

No crashes no nothing, It's just null, doesn't change. Why ?

Edit: This is the thing that i have in the manifest:

<DeviceCapability Name="usb">
    <Device Id="vidpid:184c 0001">
        <Function Type="classId:ff * *"/>
    </Device>
</DeviceCapability> 

Upvotes: 4

Views: 1434

Answers (2)

Anton Bakulev
Anton Bakulev

Reputation: 306

I just note for memory that it there is null after UsbDevice.FromIdAsync one should check the following:

  1. Presence of the device with WinUsb driver in device manager.

  2. Presence of multistring parameter DeviceInterfaceGUIDs with generated GUID in registry

    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_184C&PID_0001\8000013\Device Parameters]
    "DeviceInterfaceGUIDs"=hex(7):7b,00,32,00,34,00,42,00,35,00,37,00,46,00,34,00,\
    37,00,2d,00,41,00,37,00,41,00,43,00,2d,00,34,00,46,00,41,00,32,00,2d,00,39,\
    00,43,00,31,00,33,00,2d,00,32,00,38,00,36,00,42,00,30,00,33,00,34,00,46,00,\
    
  3. Presence of appropriate DeviceCapability in Package.appxmanifest

    <Capabilities>
        <DeviceCapability Name="usb">
          <Device Id="vidpid:184C 0001">
            <Function Type="classId:ff * *" />
            <Function Type="name:vendorSpecific" />
          </Device>
        </DeviceCapability>
    

Upvotes: 2

Ahmad45123
Ahmad45123

Reputation: 472

I found the problem, the WInUSB driver that Windows installed for me didn't work for some reason, I had to install another one.

Upvotes: 0

Related Questions