简体   繁体   中英

How to find out status of a usb device using c#?

i am creating a project related to power consumed by our computer systems. now my requirement is , i need to find out power consumed by a usb device(like pendrive) in the system. can anybody plz help me.

I don't think you can because the USB specification seems not to mention anything about delivering those measurements. The only information I know you can get is if the device is a low-power or high-power device. For USB 2.0 that is 100mA or 500mA with a voltage between 4.4 and 5.25V. So a low-power power device may consume from almost 0 to 5.25*0.1=0,525W and a high-power up to 5.25*0.5=2.625W.

Unfortunately the WMI classes doesn't seem to give you even that information but that could be just me looking at the wrong places.

//using System.Management
var USBDevices = new ManagementObjectSearcher(@"Select * From Win32_USBControllerDevice");
foreach (var device in USBDevices.Get())
{
    foreach (var prop in device.Properties)
    {
        Console.WriteLine(prop.Name + " : " + prop.Value);
    }
}

您可以看看http://www.sharpdevelop.net/OpenSource/SharpUSBLib/default.aspx SharpDevelop的创建者提供的USB库(至少在同一服务器上)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM