Beispiel #1
0
 private void DeviceWatcher_Removed(DeviceWatcher sender, DeviceInformationUpdate deviceInfoUpdate)
 {
     if (sender == deviceWatcher)
     {
         this.Dispatcher.Invoke(() =>
         {
             BluetoothLEDeviceDisplay bleDeviceDisplay = FindBluetoothLEDeviceDisplay(deviceInfoUpdate.Id);
             if (bleDeviceDisplay != null)
             {
                 KnownDevices.Remove(bleDeviceDisplay);
             }
         });
     }
 }
Beispiel #2
0
        private void DeviceWatcher_Added(DeviceWatcher sender, DeviceInformation deviceInfo)
        {
            Console.Write(deviceInfo.Name.ToString() + " ");
            Console.Write("---IsPresent: " + deviceInfo.Properties["System.Devices.Aep.IsPresent"].ToString());
            Console.Write("---IsConnectable: " + deviceInfo.Properties["System.Devices.Aep.Bluetooth.Le.IsConnectable"]);
            Console.WriteLine("---RSSI = " + deviceInfo.Properties.Single(d => d.Key == "System.Devices.Aep.SignalStrength").Value);

            this.Dispatcher.Invoke(() =>
            {
                if ((bool)deviceInfo.Properties["System.Devices.Aep.Bluetooth.Le.IsConnectable"])
                {
                    var ekoDevice = new BluetoothLEDeviceDisplay(deviceInfo);

                    if (KnownDevice(ekoDevice.Id.ToString()))
                    {
                        KnownDevices.Add(ekoDevice);
                    }
                }
            });
        }
Beispiel #3
0
        private async Task GetServicesAsync(BluetoothLEDeviceDisplay device)
        {
            DeviceInformation deviceInfo = await DeviceInformation.CreateFromIdAsync(device.Id);

            deviceInfo.Pairing.Custom.PairingRequested += CustomOnPairingRequested;
            var result = await deviceInfo.Pairing.Custom.PairAsync(DevicePairingKinds.ConfirmOnly, DevicePairingProtectionLevel.Encryption);

            if (result.Status.ToString() == "Paired" || result.Status.ToString() == "AlreadyPaired" || result.Status.ToString() == "OperationAlreadyInProgress")
            {
                connectedDevice = deviceInfo;
                var pairedDevice = await BluetoothLEDevice.FromIdAsync(deviceInfo.Id);

                GattDeviceServicesResult services;
                try
                {
                    services = await pairedDevice.GetGattServicesAsync(BluetoothCacheMode.Uncached);
                }
                catch
                {
                    services = await pairedDevice.GetGattServicesAsync(BluetoothCacheMode.Uncached);
                }

                if (services.Status == GattCommunicationStatus.Success)
                {
                    foreach (var service in services.Services)
                    {
                        ListServices.Items.Add(service);
                    }
                    connected   = true;
                    last_device = deviceInfo;
                }
            }
            else
            {
                connected = false;
            }
        }
Beispiel #4
0
 private void DeviceWatcher_Updated(DeviceWatcher sender, DeviceInformationUpdate deviceInfoUpdate)
 {
     if (sender == deviceWatcher)
     {
         this.Dispatcher.Invoke(async() =>
         {
             BluetoothLEDeviceDisplay bleDeviceDisplay = FindBluetoothLEDeviceDisplay(deviceInfoUpdate.Id);
             if (bleDeviceDisplay != null)
             {
                 bleDeviceDisplay.Update(deviceInfoUpdate);
                 return;
             }
             else
             {
                 var deviceInfo = await DeviceInformation.CreateFromIdAsync(deviceInfoUpdate.Id);
                 if ((bool)deviceInfo.Properties["System.Devices.Aep.Bluetooth.Le.IsConnectable"])
                 {
                     bleDeviceDisplay = new BluetoothLEDeviceDisplay(deviceInfo);
                     KnownDevices.Add(bleDeviceDisplay);
                 }
             }
         });
     }
 }