コード例 #1
0
        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");
            }
        }
コード例 #2
0
        static string PrettyPrint(AdvertisementReceivedEventArgs e)
        {
            var builder = new StringBuilder();

            builder.Append(e.Advertisement.LocalName);
            builder.Append(" @ ");
            builder.AppendLine(e.Address.ToString());
            foreach (var uuid in e.Advertisement.ServiceUuids)
            {
                builder.Append("\t");
                builder.AppendLine(uuid.ToString());
            }
            return(builder.ToString());
        }
コード例 #3
0
        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);
        }