private async Task DoConnect() { try { //Always stop scanning before trying to connect to a device scanner.Stop(); addLog($"<Connect> Last BLE Address = {this.lastBleAddress.ToString("X")}"); if (this.lastBleAddress == 0) { addLog($"- Connect Error BLE Address"); return; } con = new BLEAuthenticatorConnector(); //con.PacketSizeByte = 155; // AllinPass con.ConnectedDevice += OnConnectedDevice; con.DisconnectedDevice += OnDisconnectedDevice; con.KeepAlive += OnKeepAlive; var result = await con.ConnectAsync(this.lastBleAddress); if (result == false) { addLog("- Connect Error"); } addLog($"Connect OK"); } catch (Exception ex) { addLog($"- Connect Error Exception: {ex.Message}"); } }
private async void OnFindDevice(object sender, g.FIDO2.CTAP.BLE.BLEAuthenticatorScanner.FindDeviceEventArgs e) { scannerBLE.Stop(); addressBLE = e.BluetoothAddress; var ret = await this.connectBLE(); if (ret == false) { return; } // UIスレッドで実行するおまじない var ignored = this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(async() => { var app = (MainWindow)Application.Current.MainWindow; var att = await app.Register(conBLE, app.RPID, app.Challenge, this.TextPIN.Text); if (att == null) { return; } if (page == null) { page = new Page11(att); } this.NavigationService.Navigate(page); })); }
private void ButtonPairUnpair_Click(object sender, RoutedEventArgs e) { try { //Always stop scanning before trying to connect or pair to a device scanner?.Stop(); var addressBytes = BitConverter.GetBytes(this.lastBleAddress).Reverse(); var filter = new byte[] { 0x00 }; var address = string.Join(":", addressBytes.Except(filter).Select(x => x.ToString("x2"))); addLog($"<Pair> Last BLE Address = {address}"); //Store if we are pairing or unpairing pairAction = (sender == ButtonPair) ? PairingAction.Pair : PairingAction.Unpair; this.authenticatorPair = new BLEAuthenticatorPair(); this.authenticatorPair.GetDevice += Pair_GetDevice; this.authenticatorPair.Start(address); } catch (Exception ex) { addLog($"- Pair Error Exception: {ex.Message}"); } }