开发者

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

开发者 https://www.devze.com 2023-01-18 15:19 出处:网络
i am creating a project related to po开发者_JAVA技巧wer consumed by our computer systems. now my requirement is ,

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

精彩评论

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

关注公众号