private async void BtUnpair() { rootPage.StatusBar("Paring Started Please Wait...", BarStatus.Warnning); Btdevice deviceInfoDisp = resultListView.SelectedItem as Btdevice; DeviceUnpairingResult dupr = await deviceInfoDisp.DeviceInformation.Pairing.UnpairAsync(); rootPage.StatusBar("Unparing Result" + dupr.Status.ToString(), dupr.Status == DeviceUnpairingResultStatus.Unpaired ? BarStatus.Sucess : BarStatus.Error); }
// serial port connect optional not woking with bluetooth. public async void Connect() { Btdevice btdevice = resultListView.SelectedItem as Btdevice; var serialPort = await SerialDevice.FromIdAsync(btdevice.Id); serialPort.ReadTimeout = TimeSpan.FromMilliseconds(1000); serialPort.WriteTimeout = TimeSpan.FromMilliseconds(1000); serialPort.BaudRate = 9600; serialPort.Parity = SerialParity.None; serialPort.StopBits = SerialStopBitCount.One; serialPort.DataBits = 8; }
private async void Connect_btn_Click(object sender, RoutedEventArgs e) { Connect_btn.IsEnabled = false; if (resultListView.SelectedItem == null) { rootPage.StatusBar("please selet an item to connect", BarStatus.Error); return; } disconnect_btn.Visibility = Visibility.Visible; // selecting bluetooth device Btdevice btSelectedDevice = resultListView.SelectedItem as Btdevice; // saving device in Local Setting For Later Use in Auto Reconnect var applicationData = Windows.Storage.ApplicationData.Current; var localSettings = applicationData.LocalSettings; localSettings.Values["LastDeviceId"] = btSelectedDevice.Id; try { if (await DeviceEventHandler.Current.ConnectAsyncFromId(btSelectedDevice.Id)) { rootPage.MainPage_Navigate_Frame(typeof(Page2)); } } catch (Exception ex) { ContentDialog cDialog = new ContentDialog() { Title = "Bluetooth", Content = "Please enable Bluetooth first.", IsPrimaryButtonEnabled = true, PrimaryButtonText = "Exit", }; // if bluetooth is ni=ot enabled then msg popup if (await cDialog.ShowAsync() == ContentDialogResult.Primary) { cDialog.Hide(); } disconnect_btn.Visibility = Visibility.Collapsed; Connect_btn.IsEnabled = true; } }
private void PairUnpair_btn_Click(object sender, RoutedEventArgs e) { resultListView.IsEnabled = false; Btdevice deviceInfoDisp = resultListView.SelectedItem as Btdevice; if (deviceInfoDisp == null) { rootPage.StatusBar("Please Select the device", BarStatus.Error); resultListView.IsEnabled = true; return; } if (deviceInfoDisp.IsPared) { BtUnpair(); } else { BtPair(); } resultListView.IsEnabled = true; }