private async void Watcher_Received(object sender, AdvertisementReceivedEventArgs e) { try { // make sure this is the right kind of hub if (!e.Advertisement.ManufacturerData[0x0397].Span.SequenceEqual(manfuacturerData.Span)) { return; } // ignore duplicate adverts if (ads.ContainsKey(e.Address)) { ads[e.Address] = e; return; } var device = await Device.FromAddressAsync(e.Address); var connection = await BLEConnection.FromDeviceAsync(device); var hub = new Hub(connection); HubConnected?.Invoke(this, hub); } catch (Exception ex) { logger?.LogDebug(ex, "Unhandled exception in HubWatcher.Watcher_Received"); } }
private async void Watcher_Received(object sender, AdvertisementReceivedEventArgs e) { try { if (pendingAddresses.Contains(e.Address)) { return; } pendingAddresses.Add(e.Address); var device = await Device.FromAddressAsync(e.Address); var connection = await BLEConnection.FromDeviceAsync(device); var hub = new Hub(connection); HubConnected?.Invoke(this, hub); } catch (Exception ex) { logger?.LogDebug(ex, "Unhandled exception in Watcher_Received"); } pendingAddresses.Remove(e.Address); }