USB端口电流值 [英] USB port current value

查看:282
本文介绍了USB端口电流值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时有可能得到USB端口电流值,当我插上设备的呢?

Is it possible to get the USB port current value when I plug the device in it?

以编程方式使用C#中的值应该是可用的。我需要第二个参数是USB节省功耗模式。属性的正确名称是允许计算机关闭此设备以节约电源。

The value should be available programmatically using C#. The second parameter I need is 'USB save power mode'. The correct name of the property is "Allow the computer to turn off this device to save power".

我设法从它正确地检测装置(如果它是连接或断开),并读取数据。

I managed to detect the device (if it is connected or disconnected) and read data from it correctly.

难道这两个楼盘都属于USB设备或USB端口?

Do these two properties belong to USB device or to USB port?!

了WinUSB阿比没有给我明确的回答我的问题。

WinUSB Api did not give me clear answers to my questions.

推荐答案

您可以使用WMI在获得USB端口属性

you can use the WMI the get the USB port properties

public class MyClass
{
    public static void Main()
    {
        var usbDevices = GetUSBDevices();

        foreach (var usbDevice in usbDevices)
        {
            Console.WriteLine("Device ID: {0}, PNP Device ID: {1}, Description: {2}",
                usbDevice.DeviceID, usbDevice.PnpDeviceID, usbDevice.Description);
        }
    }

    static List<USBDeviceInfo> GetUSBDevices()
    {
        List<USBDeviceInfo> devices = new List<USBDeviceInfo>();

        var searcher = new ManagementObjectSearcher(@"Select * From Win32_SerialPort");

        foreach (var device in searcher.Get())
        {
            devices.Add(new USBDeviceInfo(
            (string)device.GetPropertyValue("DeviceID"),
            (string)device.GetPropertyValue("PNPDeviceID"),
            (string)device.GetPropertyValue("Description"),
            (string)device.GetPropertyValue("Name")
            ));
        }

        return devices;
    }

    class USBDeviceInfo
    {
        public USBDeviceInfo(string deviceID, string pnpDeviceID, string description, string name)
        {
            this.DeviceID = deviceID;
            this.PnpDeviceID = pnpDeviceID;
            this.Description = description;
            this.Name = name;
        }
        public string DeviceID { get; private set; }
        public string PnpDeviceID { get; private set; }
        public string Description { get; private set; }
        public string Name { get; private set; }

    }
}

看看下面的属性列表

have a look at the below for the properties list

可用性应该包含你正在寻找的信息

Availability should contain the info you are looking for

http://msdn.microsoft。 COM / EN-US /库/ aa394413%28V = vs.85%29.aspx

这篇关于USB端口电流值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆