USB如何获取设备信息

时间:2016-06-22 05:56:40

标签: usb uwp

如何在UWP应用程序中获取通过USB端口连接的设备信息,也在哪个端口。我怎么能检查电话。我还可以检查设备外部电源,意味着设备通过适配器或USB电缆充电。

1 个答案:

答案 0 :(得分:0)

您可以在此处查看评论和代码UsbDevice class

请参阅以下代码:

protected override async void OnLaunched1(LaunchActivatedEventArgs args)
{
    UInt32 vid = 0x045E;
    UInt32 pid = 0x078F;

    string aqs = UsbDevice.GetDeviceSelector(vid, pid);

    var myDevices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(aqs, null);

    if (myDevices.Count == 0)
    {
        ShowError("Device not found!");
        return;
    }

    UsbDevice device = await UsbDevice.FromIdAsync(myDevices[0].Id);

   // Send a control transfer. 

   UsbSetupPacket initSetupPacket = new UsbSetupPacket() 
   { 
       Request = initRequest,
       RequestType = new UsbControlRequestType() { 

           Recipient = UsbControlRecipient.DefaultInterface,

           ControlTransferType = UsbControlTransferType.Vendor 
       } 
   };

   await device.SendOutControlTransferAsync(initSetupPacket);

}

您可以从中循环设备信息以获取详细信息。请检查您是否能找到所需的信息。

相关问题