Пример #1
0
        private static List <string> FromBT()
        {
            List <string> btResult;

            btResult = BTUtils.GetNearbyRemoteAddresses(TimeSpan.FromSeconds(1));
            if (btResult.Count == 0)
            {
                btResult = BTUtils.GetNearbyRemoteAddresses(TimeSpan.Zero);
            }
            for (int i = 0; i < btResult.Count; i++)
            {
                btResult[i] = BTUtils.FormatBtAddress(btResult[i], null, "N");
                DebugLog.write("FindBTAddress.FromBT will return " + btResult[i]);
            }
            return(btResult);
        }
Пример #2
0
        void TimerFindBtAddress_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            timerFindBtAddress.Stop();
            if (InvokeRequired)
            {
                this.comboBtAddr.Invoke((MethodInvoker) delegate
                {
                    comboBtAddr.Text    = "Searching";
                    comboBtAddr.Enabled = false;
                });
            }

            List <string> btAddr = FindBtAddress.Find(txtProductId.Text.Remove(0, 2), txtVendorId.Text.Remove(0, 2));

            if (InvokeRequired)
            {
                this.comboBtAddr.Invoke((MethodInvoker) delegate
                {
                    comboBtAddr.Items.Clear();
                    foreach (string addr in btAddr)
                    {
                        comboBtAddr.Items.Add(BTUtils.FormatBtAddress(addr, null, "C"));
                    }
                    comboBtAddr.Items.Add("Search again");
                    if (comboBtAddr.Text.Length != 12 && comboBtAddr.Text.Length != 17 && btAddr.Count == 1)
                    {
                        comboBtAddr.Text = BTUtils.FormatBtAddress(btAddr[0], null, "C");
                    }
                    else
                    {
                        comboBtAddr.Text = "";
                    }
                    comboBtAddr.Enabled = true;
                });
            }
        }
Пример #3
0
        private static List <string> FromReg(string pid, string vid)
        {
            List <string>      result = new List <string>();
            List <RegistryKey> regResult;

            try
            {
                string regFilter;
                if (vid.ToLower().Contains("x"))
                {
                    regFilter = vid.Substring(2);
                }
                else
                {
                    regFilter = vid;
                }
                if (pid.ToLower().Contains("x"))
                {
                    regFilter += "_PID&" + pid.Substring(2);
                }
                else
                {
                    regFilter += "_PID&" + pid;
                }

                regResult = RegUtils.GetKeys(Registry.LocalMachine, regFilter, "Bluetooth_UniqueID");
                foreach (RegistryKey k in regResult)
                {
                    try
                    {
                        string v = (string)k.GetValue("Bluetooth_UniqueID");
                        if (v.Length != 0 && v.Contains("#") && v.Contains("_") && (v.IndexOf("_") - v.IndexOf("#")) == 13)
                        {
                            v = v.Substring(v.IndexOf("#") + 1, 12);
                            v = BTUtils.FormatBtAddress(v, null, "N");
                            if (v != "")
                            {
                                if (!result.Contains(v))
                                {
                                    DebugLog.write("FindBTAddress.FromReg will return " + v);
                                    result.Add(v);
                                }
                            }
                            else
                            {
                                DebugLog.write("FindBTAddress.FromReg parsing returned the empty String (" + (string)k.GetValue("Bluetooth_UniqueID") + ")");
                            }
                        }
                    }
                    catch
                    {
                        try
                        {
                            DebugLog.write("FindBTAddress.FromReg Failed while parsing" + k.Name);
                        }
                        catch
                        {
                            DebugLog.write("FindBTAddress.FromReg Failed while parsing some key ..");
                        }
                    }
                }
                return(result);
            }
            catch
            {
                DebugLog.write("FindBTAddress.FromReg Failed");
                return(result);
            }
        }