Example #1
0
 private void BtnStopScan_Clicked(object sender, EventArgs e)
 {
     Windesheart.StopScanning();
     Device.BeginInvokeOnMainThread(delegate {
         StatusText.Text       = "Procura cancelada.";
         BtnStopScan.IsEnabled = false;
     });
 }
Example #2
0
        //SCAN
        private async void BtnScan_Clicked(object sender, EventArgs e)
        {
            if (Windesheart.IsScanning())
            {
                Windesheart.StopScanning();
                Device.BeginInvokeOnMainThread(delegate {
                    StatusText.Text = "Inicie a procura.";
                });
            }
            else
            {
                if (Windesheart.AdapterStatus == AdapterStatus.PoweredOff)
                {
                    await Application.Current.MainPage.DisplayAlert("Bluetooth está desativado",
                                                                    "Por favor ative o Bluetooth para iniciar a procura.", "OK");

                    Device.BeginInvokeOnMainThread(delegate {
                        StatusText.Text = "Bluetooth desativado.";
                    });
                    return;
                }
            }

            if (Windesheart.StartScanning(WhenDeviceFound))
            {
                StatusText.Text = "A Procurar...";
                Console.WriteLine("Scanning started!");
                BtnStopScan.IsEnabled = true;
            }
            else
            {
                Device.BeginInvokeOnMainThread(delegate {
                    StatusText.Text = "Não foi possivel iniciar a procura.";
                });

                await Task.Delay(1500);

                Windesheart.StopScanning();
                Console.WriteLine("Scanning Stopped!");
            }
        }
Example #3
0
        public async void WhenDeviceFound(BLEScanResult result)
        {
            Device.BeginInvokeOnMainThread(delegate {
                StatusText.Text = "Dispositivo Encontrado.";
            });

            Console.WriteLine("Device found!");

            BLEDevice          device = result.Device;
            int                Rssi   = result.Rssi;
            IAdvertisementData data   = result.AdvertisementData;

            await Task.Delay(1500);

            Windesheart.StopScanning();
            try
            {
                device.Connect(OnConnectionFinished);
            }
            catch (Exception e1)
            {
                Console.WriteLine("ERRO - - - -" + e1);
            }
        }
Example #4
0
 public void OnDisappearing()
 {
     Windesheart.StopScanning();
 }