public override void MoveNextPage() { timer.Stop(); Trace.WriteLine("AddNewDevice Timer is stopped"); timer.Tick -= timer_TickAsync; timer.IsEnabled = false; bleBrowser?.StopScan(); Array.Copy(SelectedItem.Mac, 0, HIOStaticValues.blea.mac, 0, 6); //Array.Resize(ref HIOStaticValues.blea.name, Encoding.ASCII.GetBytes(SelectedItem.Title).Length); Array.Copy(Encoding.ASCII.GetBytes(SelectedItem.Title), 0, HIOStaticValues.blea.name, 0, Encoding.ASCII.GetBytes(SelectedItem.Title).Length); if (SelectedItem?.IsBLE ?? false) { HIOStaticValues.DirectBluetooth = true; //HIOStaticValues.EventCheckDevice.Set(); //HIOStaticValues._signalCheckDevice.WaitOne(); //FREE var deviceInfo = BLEBrowser.FindConnectedDevice(); if (deviceInfo != null) { HIOStaticValues.BaS.devInfo = deviceInfo; HIOStaticValues.BaS.dev = new BLEDevice(); HIOStaticValues.BaS.dev.Open(deviceInfo); } HIOStaticValues.EventCheckDevice.Set(); } //else //{ // HIOStaticValues.DirectBluetooth = false; //} base.MoveNextPage(); }
public async void LoadBLEDeviceAsync() { try { timer.IsEnabled = false; timer.Stop(); timer.Tick -= timer_TickAsync; HIOStaticValues.BaS.dev.Dispose(); if (HIOStaticValues.IsBLESupported && HIOStaticValues.BaS.dev is HIDDev) { HIOStaticValues.BaS.dev = null; HIOStaticValues.BaS.dev = new BLEDevice(); } //HIOStaticValues.EventCheckDevice.Set(); //} ErrorOK(); IsConnecting = true; DisSearch = false; BluetoothItems.Clear(); if (bleBrowser == null) { bleBrowser = new BLEBrowser(); } bleBrowser.StopScan(); bleBrowser.StartScan(BluetoothItems, () => { App.Current.Dispatcher.Invoke(() => { if (IsInBluetoothTab && BluetoothItems?.Count == 0) { Message = NoBluetoothDeviceMessage; } else if (Message == NoBluetoothDeviceMessage) { Message = null; } }); }); await Task.Delay(2000).ContinueWith(r => { if (IsInBluetoothTab && BluetoothItems?.Count == 0) { App.Current.Dispatcher.Invoke(() => Message = NoBluetoothDeviceMessage); } IsConnecting = false; DisSearch = true; }); //await Task.Run(new Action(() => HIOStaticValues._signalCheckDevice.WaitOne())); //FREE } catch (Exception ex) { Debug.Write($"Exception BLEDevice: {ex.Message}"); } }