Esempio n. 1
0
        public static async Task <Device> GetDeviceAsync(this IAdapter1 adapter, string deviceAddress)
        {
            var devices = await BlueZManager.GetProxiesAsync <IDevice1>(BluezConstants.DeviceInterface, adapter);

            var matches = new List <IDevice1>();

            foreach (var device in devices)
            {
                if (String.Equals(await device.GetAddressAsync(), deviceAddress, StringComparison.OrdinalIgnoreCase))
                {
                    matches.Add(device);
                }
            }

            if (matches.Count > 1)
            {
                throw new Exception($"{matches.Count} devices found with the address {deviceAddress}!");
            }

            var dev = matches.FirstOrDefault();

            if (dev != null)
            {
                return(await Device.CreateAsync(dev));
            }
            return(null);
        }
Esempio n. 2
0
        public static async Task <IReadOnlyList <Device> > GetDevicesAsync(this IAdapter1 adapter)
        {
            var devices = await BlueZManager.GetProxiesAsync <IDevice1>(BluezConstants.DeviceInterface, adapter);

            return(await Task.WhenAll(devices.Select(Device.CreateAsync)));
        }