示例#1
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);
        }
示例#2
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";
                }
            }
        }
示例#3
0
        public async Task <string> FindArrivaledDevice(string serialNumber)
        {
            int count = 0;

            while (count <= config_inc.CMD_REPEAT_MAX_TIME)
            {
                UsbRegDeviceList allDevices = UsbDevice.AllDevices;
                common.m_log.Add_Debug($"find devices {allDevices.Count}");
                await CMDHelper.Adb_KillServer();

                for (int index = 0; index < allDevices.Count; index++)
                {
                    var       device = (WinUsbRegistry)allDevices[index];
                    UsbDevice usbDevice;
                    bool      result = device.Open(out usbDevice);
                    common.m_log.Add_Debug($"open device registry info page:{result}");
                    if (result)
                    {
                        if (serialNumber == usbDevice.Info.SerialString)
                        {
                            string[] locationPaths = (string[])device.DeviceProperties["LocationPaths"];
                            usbDevice.Close();
                            CMDHelper.Adb_StartServer();

                            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));
                        }
                    }
                    if (usbDevice != null)
                    {
                        usbDevice.Close();
                    }
                }
                count++;
                await Task.Delay(500);
            }
            CMDHelper.Adb_StartServer();
            return(String.Empty);
        }
示例#4
0
        public async Task <List <UsbDeviceInfoEx> > GetAllDevices()
        {
            List <UsbDeviceInfoEx> device_list = new List <UsbDeviceInfoEx>();
            UsbRegDeviceList       allDevices  = UsbDevice.AllDevices;
            await CMDHelper.Adb_KillServer();

            common.m_log.Add_Debug($"find devices {allDevices.Count}");
            for (int index = 0; index < allDevices.Count; index++)
            {
                var       device = (WinUsbRegistry)allDevices[index];
                UsbDevice usbDevice;
                bool      result = device.Open(out usbDevice);
                common.m_log.Add_Debug($"open device registry info page:{result}");
                if (result)
                {
                    string[] locationPaths = (string[])device.DeviceProperties["LocationPaths"];
                    usbDevice.Close();

                    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;

                    string portNum = filterUsbPort(locationPaths[0], man);

                    UsbDeviceInfoEx deviceInfo = new UsbDeviceInfoEx();
                    deviceInfo.Index        = -1;
                    deviceInfo.Port_Path    = portNum;
                    deviceInfo.SerialNumber = usbDevice.Info.SerialString;
                    device_list.Add(deviceInfo);
                }
                if (usbDevice != null)
                {
                    usbDevice.Close();
                }
            }
            await Task.Delay(config_inc.CMD_REPEAT_WAIT_TIME);

            CMDHelper.Adb_StartServer();
            return(device_list);
        }