Ejemplo n.º 1
0
 private void InitializeBluetoothClient()
 {
     _bluetoothClient = BluetoothClient.Instance;
     _bluetoothClient.Initialize();
     if (_bluetoothClient.IsInitialized)
     {
         _scanner = new BluetoothDeviceScanner(_bluetoothClient.Adapter, OnDiscoveredPeripheral);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Инициализация Bluetooth-модуля
        /// </summary>
        /// <returns></returns>
        public BLE_Status BLE_Init()
        {
            BluetoothClient _bluetoothClient = BluetoothClient.Instance;

            _bluetoothClient.Initialize();

            if (_bluetoothClient.Adapter == null)
            {
                return(BLE_Status.BT_NotAwailable);                                   //Bluetooth не поддерживается на этом устройстве
            }
            if (_bluetoothClient.Adapter.IsEnabled == false)
            {
                return(BLE_Status.BT_IsSwitchOff);                                               //Bluetooth выключен
            }
            if (_bluetoothClient.IsBLEEnabled == false)
            {
                return(BLE_Status.BLE_NotAwailable);                                        //Bluetooth Low Energy не поддерживается на этом устройстве
            }
            if (_bluetoothClient.IsInitialized == false)
            {
                return(BLE_Status.NotConnect);                                               //Bluetooth Уже инициализирован
            }
            Status = BLE_Status.NotConnect;

            _scanner = new BluetoothDeviceScanner(_bluetoothClient.Adapter, (BluetoothDevice dev) =>
            {
                if (DeviceList.All(d => !d.Address.Equals(dev.Address, StringComparison.OrdinalIgnoreCase)))
                {
                    if (dev.Name != null)
                    {
                        DeviceList.Add(dev);
                        onDeviceFound?.Invoke(new BLE_Device_Info()
                        {
                            Name = dev.Name, Address = dev.Address
                        });
                    }
                }
            });

            return(BLE_Status.NotConnect);
        }