UWP app cannot find/connect to USB device

前端 未结 3 1373
一向
一向 2020-12-19 08:02

I am trying to make a UWP app which connects to a USB device and then executes a series of commands, like retrieving data from the internal sensor (think of an accelerometer

3条回答
  •  -上瘾入骨i
    2020-12-19 08:27

    This is how to connect to a WinUSB device on UWP.

    public async Task> GetConnectedDeviceDefinitions(uint? vendorId, uint? productId)
    {
        var aqsFilter = "System.Devices.InterfaceClassGuid:=\"{DEE824EF-729B-4A0E-9C14-B7117D33A817}\" AND System.Devices.InterfaceEnabled:=System.StructuredQueryType.Boolean#True AND " + $" System.DeviceInterface.WinUsb.UsbVendorId:={vendorId.Value} AND System.DeviceInterface.WinUsb.UsbProductId:={productId.Value}";
    
        var deviceInformationCollection = await wde.DeviceInformation.FindAllAsync(aqsFilter).AsTask();
    
        //TODO: return the vid/pid if we can get it from the properties. Also read/write buffer size
    
        var deviceIds = deviceInformationCollection.Select(d => new DeviceDefinition { DeviceId = d.Id, DeviceType = DeviceType.Usb }).ToList();
        return deviceIds;
    }
    

    Here is a more complete answer: https://stackoverflow.com/a/53954352/1878141

    And, here is a class from the repo: https://github.com/MelbourneDeveloper/Device.Net/blob/master/src/Usb.Net.UWP/UWPUsbDeviceFactory.cs

提交回复
热议问题