C# UWP USB DeviceWatcher不';行不通

C# UWP USB DeviceWatcher不';行不通,c#,uwp,usb,trezor,C#,Uwp,Usb,Trezor,首先,我应该指出,我已经将需要通话的设备添加到我的应用程序清单中,并且我能够成功地与该设备通话。我可以通过以下线路获取设备的此设备信息: var trezorDeviceInformation = await UWPHidDevice.GetDeviceByIdSlowAsync(TrezorManager.HidId); 但是,出于某种原因,如果我试图监视具有产品id和供应商id的设备,则监视者的事件永远不会触发。我试过这个: public UWPHidDevice(uint ven

首先,我应该指出,我已经将需要通话的设备添加到我的应用程序清单中,并且我能够成功地与该设备通话。我可以通过以下线路获取设备的此设备信息:

var trezorDeviceInformation = await UWPHidDevice.GetDeviceByIdSlowAsync(TrezorManager.HidId);
但是,出于某种原因,如果我试图监视具有产品id和供应商id的设备,则监视者的事件永远不会触发。我试过这个:

    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();
    }

当我插入设备或使用设备启动应用程序时,添加的事件不会触发。我必须强调,我可以在我的应用程序中使用此设备,并且我已经三次检查了VendorId和ProductId。只是观察者不起作用。我卡住了

有人提供提示或示例应用程序吗?


编辑:我试过官方的UWP示例应用程序。我用我需要在代码和应用程序清单中使用的设备值替换了VendorId和ProductId。此示例存在相同的问题。

您的设备是否使用WinUSB驱动程序显示在设备管理器中?只有在使用WinUSB驱动程序时,您的代码才适用于我的供应商id和pid

我使用以下代码:

// 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();
//创建设备监视程序以查找Xerox设备的实例
watcher=DeviceInformation.CreateWatcher(UsbDevice.GetDeviceSelector(vendorId,productId));
watcher.Added+=新类型deventhandler(this.ondeviceaded);
watcher.Removed+=新类型deventhandler(this.OnDeviceRemoved);
watcher.EnumerationCompleted+=新类型deventhandler(this.ondevicenumerioncomplete);
watcher.Start();

最简单的方法是使用替换vendorId和productId来测试设备。但是你说官方应用程序不会编译,这很奇怪,官方示例在我这边运行得很好,所以你应该在第一步尝试让官方应用程序工作。错误:严重性代码描述项目文件行抑制状态错误你的项目没有引用“UAP,Version=v10.0.16299”框架。在project.json的“frameworks”部分添加对“UAP,Version=v10.0.16299”的引用,然后重新运行NuGet restore。CustomHidDeviceAccessI已尝试升级UWP NuGet软件包,但没有任何效果。我使用的是VS15.5.7OK。把它擦掉。我做了一个Git清理,现在应用程序正在运行。我仍然没有看到该设备,但如果我无法使示例应用正常工作,我将尝试一些方法并编辑原始帖子。我已替换清单中的Vid和Pid,以及文件SampleConfiguration.cs,但没有显示任何内容。什么是WinUSB驱动程序?它是与USB设备关联的windows驱动程序。在大多数情况下,您只需要一个INF文件来告诉Windows设备的VID和PID,以便在连接设备时使用。WinUSB.SYS用作设备管理器中的驱动程序。
// 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();