简体   繁体   English

USB端口电流值

[英]USB port current value

Is it possible to get the USB port current value when I plug the device in it?插入设备时是否可以获得USB端口电流值?

The value should be available programmatically using C#.该值应该可以使用 C# 以编程方式获得。 The second parameter I need is 'USB save power mode'.我需要的第二个参数是“USB 省电模式”。 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?!这两个属性是属于 USB 设备还是属于 USB 端口?!

WinUSB Api did not give me clear answers to my questions. WinUSB Api 没有给我明确的问题答案。

you can use the WMI the get the USB port properties您可以使用 WMI 获取 USB 端口属性

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 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:我认为您想要的大部分内容与 WinDDK 中的 WinUSB 没有任何关系,但更多的是与操作系统如何处理设备有关:

http://msdn.microsoft.com/en-us/library/aa394504%28v=VS.85%29.aspx - WMI class to access USB related info http://msdn.microsoft.com/en-us/library/aa394504%28v=VS.85%29.aspx - WMI class 访问 Z7ACA5EC618F7317328DCD7014CF 相关信息
http://www.acpi.info/DOWNLOADS/ACPIspec40a.pdf - ACPI could provide some help http://www.acpi.info/DOWNLOADS/ACPIspec40a.pdf - ACPI 可以提供一些帮助

IF you need to dig deeprer into USB see如果您需要更深入地研究 USB,请参阅
http://www.usb.org/developers - all relevant USB standards documents http://www.usb.org/developers - 所有相关的 USB 标准文档
http://www.beyondlogic.org/usbnutshell/usb1.shtml - some usefull information http://www.beyondlogic.org/usbnutshell/usb1.shtml - 一些有用的信息
http://www.libusb.org/ - a library to handle USB at a very low level http://www.libusb.org/ - 在非常低的级别处理 USB 的库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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