Esempio n. 1
0
 protected virtual void OnDeviceDiscovered(CrossBluetoothDevice BluetoothDevice)
 {
     if (DeviceDiscovered != null)
     {
         DeviceDiscovered(this, new DeviceDiscoveredEventArgs(BluetoothDevice));
     }
 }
Esempio n. 2
0
            public bool ConnectToDevice(CrossBluetoothDevice crossBluetoothDevice)
            {
                bool result = false;

                if (deviceList.Count > 0)
                {
                    var pairedDeviceSearchCount     = bluetoothAdapter.BondedDevices.Where(x => x.Name == crossBluetoothDevice.Name && x.Address == crossBluetoothDevice.Address).Count();
                    var discoveredDeviceSearchCount = deviceList.Where(x => x.Name == crossBluetoothDevice.Name && x.Address == crossBluetoothDevice.Address).Count();
                    if (pairedDeviceSearchCount > 0)
                    {
                        if (pairedDeviceSearchCount == 1)
                        {
                            var bluetoothDevice       = bluetoothAdapter.BondedDevices.First(x => x.Name == crossBluetoothDevice.Name && x.Address == crossBluetoothDevice.Address);
                            var bluetoothGatt         = bluetoothDevice.ConnectGatt(context, true, new BGattCallback());
                            var bluetoothGattServices = bluetoothGatt.Services;
                            result = true;
                            int i = 0;
                        }
                    }
                    else
                    {
                        if (discoveredDeviceSearchCount > 0)
                        {
                            if (discoveredDeviceSearchCount == 1)
                            {
                                var bluetoothDevice       = deviceList.First(x => x.Name == crossBluetoothDevice.Name && x.Address == crossBluetoothDevice.Address);
                                var bluetoothGatt         = bluetoothDevice.ConnectGatt(context, true, new BGattCallback());
                                var bluetoothGattServices = bluetoothGatt.Services;
                                result = true;
                                int i = 0;
                            }
                        }
                    }
                }
                return(result);
            }