开发者

USB port current value

Is it possible to get the USB port current value when I plug the 开发者_StackOverflow社区device in it?

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.

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

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


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/library/aa394413%28v=vs.85%29.aspx


I think that most of what you want doesn't have anything to do with WinUSB from WinDDK but more with how the OS handles devices:

http://msdn.microsoft.com/en-us/library/aa394504%28v=VS.85%29.aspx - WMI class to access USB related info
http://www.acpi.info/DOWNLOADS/ACPIspec40a.pdf - ACPI could provide some help

IF you need to dig deeprer into USB see
http://www.usb.org/developers - all relevant USB standards documents
http://www.beyondlogic.org/usbnutshell/usb1.shtml - some usefull information
http://www.libusb.org/ - a library to handle USB at a very low level

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜