1

Firstly, I should point out that I have added the device that I need to talk to in to my app's manifest, and I am able to successfully talk to the device. I am able to get this device information for the device with this line:

var trezorDeviceInformation = await UWPHidDevice.GetDeviceByIdSlowAsync(TrezorManager.HidId);

But, for some reason, if I try to watch for the device with product id, and vendor, Id, the watcher's events never fire. I have tried this:

    public UWPHidDevice(uint vendorId, uint productId)
    {
        var deviceWatcher = DeviceInformation.CreateWatcher($"System.DeviceInterface.WinUsb.UsbVendorId:={vendorId} AND System.DeviceInterface.WinUsb.UsbProductId:={productId}");
        deviceWatcher.Added += DeviceWatcher_Added;
        deviceWatcher.Removed += DeviceWatcher_Removed;
        deviceWatcher.Start();
    }

and

    public UWPHidDevice(uint vendorId, uint productId)
    {
        string aqs = UsbDevice.GetDeviceSelector(vendorId, productId);
        var deviceWatcher = DeviceInformation.CreateWatcher(aqs);
        deviceWatcher.Added += DeviceWatcher_Added;
        deviceWatcher.Removed += DeviceWatcher_Removed;
        deviceWatcher.Start();
    }

The added event never fires when I plug the device in, or start the app up with the device. I must stress that I can use this device in my app, and I have triple checked the VendorId and ProductId. It's just the watcher that doesn't work. I'm stuck.

Does anyone have tips or a sample app?

Edit: I have tried the official UWP sample app. I replaced the VendorId and ProductId with the device values that I need to use in both the code, and the app manifest. The sample has the same issue.

Christian Findlay
  • 6,770
  • 5
  • 51
  • 103
  • The simplest method is testing your device using the [Official sample](https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/CustomUsbDeviceAccess) by replacing the vendorId and productId with yourself. But you said the official app won't compile, it is odd, the official sample work well in my side, so you should try to make the official app work in the first step. – Breeze Liu - MSFT Mar 13 '18 at 05:59
  • Error: Severity Code Description Project File Line Suppression State Error Your project is not referencing the "UAP,Version=v10.0.16299" framework. Add a reference to "UAP,Version=v10.0.16299" in the "frameworks" section of your project.json, and then re-run NuGet restore. CustomHidDeviceAccess – Christian Findlay Mar 14 '18 at 07:35
  • I have tried upgrading the UWP NuGet package but it did nothing. I am using VS 15.5.7 – Christian Findlay Mar 14 '18 at 07:36
  • OK. Scratch that. I did a Git clean and now the app is running. I'm still not seeing the device, but I will try a few things and edit the original post if I can't get the sample app working. – Christian Findlay Mar 14 '18 at 07:40
  • I've replaced the Vid and Pid in the manifest, and the file SampleConfiguration.cs but nothing comes up. – Christian Findlay Mar 14 '18 at 07:49
  • This sample just has the same problem as I have described in my post. No events are fired. – Christian Findlay Mar 14 '18 at 07:54
  • I'm pretty convinced that device watcher is just broken – Christian Findlay Mar 14 '18 at 08:01
  • Is your device a [WinUSB Device](https://learn.microsoft.com/en-us/windows-hardware/drivers/usbcon/automatic-installation-of-winusb)? – Breeze Liu - MSFT Mar 14 '18 at 08:24
  • What's a WinUSB device? If you mean, can I use it in Windows? The answer is yes. If the question is, can I use it on UWP? The answer is yes. I am transferring data to and from it right now. – Christian Findlay Mar 14 '18 at 08:33

1 Answers1

1

Is you device showing up in device manager using the WinUSB driver? The code you have works for me with my vendor id and pid only when using the WinUSB driver.

I use this code:

// Create a device watcher to look for instances of the Xerox device
watcher = DeviceInformation.CreateWatcher(UsbDevice.GetDeviceSelector(vendorId, productId));

watcher.Added += new TypedEventHandler<DeviceWatcher, DeviceInformation>(this.OnDeviceAdded);
watcher.Removed += new TypedEventHandler<DeviceWatcher, DeviceInformationUpdate>(this.OnDeviceRemoved);
watcher.EnumerationCompleted += new TypedEventHandler<DeviceWatcher, Object>(this.OnDeviceEnumerationComplete);
watcher.Start();
  • What's a WinUSB driver? – Christian Findlay Oct 01 '18 at 04:12
  • It's the windows driver associated with your USB device. In most cases, you only need a INF file which tells Windows the VID and PID of your device so that when it's attached. WinUSB.SYS is used as the driver in Device Manager. – Glenn Smith Oct 02 '18 at 12:19