示例#1
0
        private Stream GetBleStream(IBluetoothLowEnergyDevice device)
        {
            var stream = new BluetoothLowEnergyStream(device, () =>
            {
                _acceptedDevices.Remove(device);
                _adapter.DisconnectDevice(device);
            });

            _acceptedDevices.Add(device);
            return(stream);
        }
示例#2
0
 public void DisconnectDevice(IBluetoothLowEnergyDevice device)
 {
     if (device is BleDevice wrap)
     {
         _adapter.DisconnectDevice(wrap.Device);
     }
     else
     {
         throw new InvalidOperationException(
                   $"Only pass {nameof(IBluetoothLowEnergyDevice)} instances that were retrieved from the {nameof(ConnectedDevices)} list");
     }
 }
        public BluetoothLowEnergyStream(IBluetoothLowEnergyDevice device, Action onDispose)
        {
            _device    = device;
            _onDispose = onDispose;

            var tcs = new TaskCompletionSource <int>();

            _device.DiscoverServicesAsync().ContinueWith(async _ =>
            {
                await ServicesDiscovered();
                tcs.SetResult(0);
            });
            _initializationTask = tcs.Task;
        }
示例#4
0
 public bool Equals(IBluetoothLowEnergyDevice other)
 {
     return(other is BleDevice otherDevice && Device == otherDevice.Device);
 }