示例#1
0
        async void ShowConnectedDevices()
        {
            await CMDHelper.Adb_KillServer();

            UsbRegDeviceList allDevices = UsbDevice.AllDevices;

            m_log.Add($"find devices {allDevices.Count}");
            for (int index = 0; index < allDevices.Count; index++)
            {
                var device = (WinUsbRegistry)allDevices[index];

                UsbDevice usbDevice;
                if (device.Open(out usbDevice))
                {
                    //lbl_deviceInfo.Text += device.DeviceID + "\r\n";
                    lbl_deviceInfo.Text += "Serial Number: " + usbDevice.Info.SerialString + "\r\n";
                    string[] locationPaths = (string[])device.DeviceProperties["LocationPaths"];

                    P_ID p_id = P_ID.NULL;
                    V_ID v_id = V_ID.NULL;
                    Enum.TryParse <P_ID>(device.Pid.ToString(), out p_id);
                    Enum.TryParse <V_ID>(device.Vid.ToString(), out v_id);
                    DeviceManufactory man = new DeviceManufactory();
                    man.p_id             = p_id;
                    man.v_id             = v_id;
                    man.company_name     = device.FullName;
                    lbl_deviceInfo.Text += "USB Port: " + filterUsbPort(locationPaths[0], man) + "\r\n";
                    lbl_deviceInfo.Text += "\r\n";
                }
            }
        }
示例#2
0
        string findArrivaledDevice(string serialNumber)
        {
            string           returnStr  = String.Empty;
            UsbRegDeviceList allDevices = UsbDevice.AllDevices;

            //Debug.WriteLine($"find devices {allDevices.Count}");
            m_log.Add($"find devices {allDevices.Count}");
            for (int index = 0; index < allDevices.Count; index++)
            {
                var       device = allDevices[index];
                UsbDevice usbDevice;
                bool      result = device.Open(out usbDevice);
                m_log.Add($"open device :{serialNumber} registry info page:{result}");
                if (result)
                {
                    if (serialNumber == usbDevice.Info.SerialString)
                    {
                        string[] locationPaths = (string[])device.DeviceProperties["LocationPaths"];
                        P_ID     p_id          = P_ID.NULL;
                        V_ID     v_id          = V_ID.NULL;
                        Enum.TryParse <P_ID>(device.Pid.ToString(), out p_id);
                        Enum.TryParse <V_ID>(device.Vid.ToString(), out v_id);

                        DeviceManufactory man = new DeviceManufactory();
                        man.p_id         = p_id;
                        man.v_id         = v_id;
                        man.company_name = device.FullName;
                        return(filterUsbPort(locationPaths[0], man));
                    }
                }
            }
            UsbDevice.Exit();
            return(returnStr);
        }
示例#3
0
        string filterUsbPort(string locationPath, DeviceManufactory manufactory)
        {
            string usb_port = String.Empty;

            string[] arr = locationPath.Split('#');
            foreach (var node in arr)
            {
                if (node.Contains("USB("))
                {
                    int port = -1;
                    Int32.TryParse(node.Substring(4, 1), out port);
                    if (port > -1)
                    {
                        usb_port += "#" + port.ToString("D4");
                    }
                }
            }
            if (manufactory.p_id == P_ID.SAMSUNG && manufactory.v_id == V_ID.SAMSUNG)
            {
                usb_port = usb_port.Substring(0, usb_port.Length - 5);// 去掉最后一个USB位置
            }
            return(usb_port);
        }