static public object GetDeviceInformation(string readername)
        {
            foreach (long item in _deviceDB)
            {
                string name;

                Radio.GetRemoteName(item, out name);

                if (name == readername)
                {
                    return(item);
                }
            }

            return(null);
        }
        static void Manager_OnDeviceFound(object Sender, wclBluetoothRadio Radio, long Address)
        {
            wclBluetoothDeviceType DevType = wclBluetoothDeviceType.dtMixed;
            Int32 Res = Radio.GetRemoteDeviceType(Address, out DevType);

            if (Res != wclErrors.WCL_E_SUCCESS)
            {
                CSLibrary.Debug.WriteLine("Error: 0x" + Res.ToString("X8"));
            }
            else
            {
                switch (DevType)
                {
                case wclBluetoothDeviceType.dtBle:
                {
                    CSLibrary.DeviceFinder.DeviceInfomation di = new CSLibrary.DeviceFinder.DeviceInfomation();
                    string DevName;
                    sbyte  RSSI;

                    Res = Radio.GetRemoteRssi(Address, out RSSI);
                    if (Res != wclErrors.WCL_E_SUCCESS)
                    {
                        RSSI = 0;
                    }
                    Res = Radio.GetRemoteName(Address, out DevName);
                    if (Res != wclErrors.WCL_E_SUCCESS)
                    {
                        di.deviceName = DevName = "Error: 0x" + Res.ToString("X8");
                    }
                    else
                    {
                        di.deviceName = DevName;
                    }

                    di.ID     = (uint)_deviceDB.Count;
                    di.macAdd = Address;
                    di.nativeDeviceInformation = null;

                    _deviceDB.Add(Address);

                    RaiseEvent <DeviceFinderArgs>(OnSearchCompleted, new DeviceFinderArgs(di));
                }
                break;
                }
            }
        }
        private void Manager_OnDiscoveringCompleted(object sender, wclBluetoothRadio radio, int error)
        {
            if (_devices.Count == 0)
            {
                MessageBox.Show("No BLE devices were found.", "Discovering for BLE devices", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
            else
            {
                // Here we can update found devices names.
                foreach (var key in _devices.Keys)
                {
                    var address = Convert.ToInt64(key, 16);

                    var item = lvDevices.Items.Add(address.ToString("X12"));

                    string devName;
                    var    res = radio.GetRemoteName(address, out devName);
                    if (devName.Contains("SCH"))
                    {
                        if (res != wclErrors.WCL_E_SUCCESS)
                        {
                            item.SubItems.Add("Error: 0x" + res.ToString("X8"));
                        }
                        else
                        {
                            item.SubItems.Add(devName);
                        }
                    }
                    else
                    {
                        lvDevices.Items.Remove(item);
                    }
                }
            }

            TraceEvent(0, "Discovering completed", "", "");
        }
Exemple #4
0
        void Manager_OnDeviceFound(object Sender, wclBluetoothRadio Radio, long Address)
        {
            int    Res  = Radio.GetRemoteName(Address, out string NameOut);
            string Name = Res == wclErrors.WCL_E_SUCCESS ? NameOut : "N/A";

            Res = Radio.GetRemoteRssi(Address, out sbyte RssiOut);
            int    Rssi    = Res == wclErrors.WCL_E_SUCCESS ? RssiOut : 1;
            string addrRaw = Address.ToString("x12");
            string addrstr = addrRaw.Substring(0, 2);

            for (int i = 2; i < 12; i += 2)
            {
                addrstr += ":" + addrRaw.Substring(i, 2);
            }

            if (addrstr.StartsWith("48:d0:cf") && !addressList.Contains(addrstr))
            {
                //Console.WriteLine("Found " + addrstr + " name " + Name);
                addressList.Add(addrstr);
                nameList.Add(Name);
                rssiList.Add(Rssi);
            }
        }