开发者

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

i am creating a project related to po开发者_JAVA技巧wer 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);
    }
}


You might have a look at http://www.sharpdevelop.net/OpenSource/SharpUSBLib/default.aspx An USB library by the creators of SharpDevelop (at least on the same server)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜