private void _bluetoothManager_PumpDiscovered(object sender, PumpDiscoveredEventArgs e) { // Do we know about this pump? PumpModel pump = _pairedPumps.Where(p => p.Id == e.Pump.Id).FirstOrDefault(); if (pump != null) { // Set the name if this pump was found before e.Pump.Name = pump.Name; // If this is a pump we know about and have paired with, pair automatically if (!_bluetoothManager.IsPaired) { _bluetoothManager.Connect(e.Pump); } } else { // Otherwise, add it as a new pump Xamarin.Forms.Device.BeginInvokeOnMainThread(() => { if (!_newPumps.Contains(e.Pump)) { _newPumps.Add(e.Pump); } }); } }
private async void LvwItems_ItemSelected(object sender, SelectedItemChangedEventArgs e) { try { if (lvwItems.SelectedItem != null) { device = lvwItems.SelectedItem as IDevice; connected2Device = await btManager.Connect(device, adapter); if (connected2Device) { CacheProvidor.Set <IDevice>("device", device, DateTime.Now.AddDays(1)); characteristic = await btManager.GetCharasteric(device); CacheProvidor.Set <ICharacteristic>("characteristic", characteristic, DateTime.Now.AddDays(1)); await Navigation.PushModalAsync(new NavigationPage(new MasterPage())); } else { await DisplayAlert("Foutmelding", "Verbinding maken is mislukt. We scannen opnieuw voor u.", "Ok"); StartUp(); } } lvwItems.SelectedItem = null; } catch (Exception ex) { await StepOutManager.Writelog(ex); await DisplayAlert("Fout", "Er is iets misgelopen bij het connecteren met een bluetooth device, als dit blijft voorkomen gelieve contact op te nemen met de suport.", "Ok"); } }
private void AddBluetooth(object sender, RoutedEventArgs e) { bluetoothManager = new BluetoothManager(); bluetoothManager.OnConnect += OnBluetoothConnect; bluetoothManager.Connect(); }