USB将如何获取设备信息

How will USB get devices information

我如何在 UWP 应用程序中获取通过 USB 端口连接的设备信息,以及在哪个端口。以及如何检查 phone 的情况。我还可以检查设备的外部电源吗,意味着设备正在通过适配器或 USB 数据线充电。

您可以从这里查看备注和代码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);

}

您可以从中循环 设备信息 了解详细信息。请检查是否可以找到您想要的信息。