public async Task EnableNotificationsAsync(Tuple <Guid, Guid> gattChar, Action <byte[]> handler)
        {
            var value = WarbleGatt.FindCharacteristic(gattChar.Item2.ToString());

            if (value == null)
            {
                throw new InvalidOperationException(string.Format("Characteristic '{0}' does not exist", gattChar.Item2));
            }
            else
            {
                await value.EnableNotificationsAsync();

                value.OnNotificationReceived = bytes => handler(bytes);
            }
        }
Exemplo n.º 2
0
        private static async Task MainAsync(string[] args)
        {
            async Task ReadDevInfo(string mac)
            {
                var gatt = new Gatt(mac);
                await gatt.ConnectAsync();

                string[] uuids = new string[] {
                    "00002a26-0000-1000-8000-00805f9b34fb",
                    "00002a24-0000-1000-8000-00805f9b34fb",
                    "00002a27-0000-1000-8000-00805f9b34fb",
                    "00002a29-0000-1000-8000-00805f9b34fb",
                    "00002a25-0000-1000-8000-00805f9b34fb"
                };

                foreach (var id in uuids)
                {
                    var gattchar = gatt.FindCharacteristic(id);

                    Console.Write(mac + " -> ");
                    if (gattchar == null)
                    {
                        Console.Write(id);
                        Console.WriteLine(": Does not exist");
                    }
                    else
                    {
                        Console.Write(gattchar.Uuid);
                        Console.WriteLine(string.Format(": {0}", System.Text.Encoding.ASCII.GetString(await gattchar.ReadAsync())));
                    }
                }
            }

            await Task.WhenAll(args.Select(_ => ReadDevInfo(_)));
        }