Ejemplo n.º 1
0
        /// <summary>
        /// Gets all devices based on their pairing state. Takes much longer to find unpaired devices than paired devices
        /// </summary>
        /// <param name="Connected">True to look for paired devices, false to look for unpaired devices</param>
        public static void DevicesWithPairingStatus(bool Paired)
        {
            CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                List <GattDevice> returnDevices = new List <GattDevice>();
                string filter = BluetoothLEDevice.GetDeviceSelectorFromPairingState(Paired);
                DeviceInformationCollection infos = await DeviceInformation.FindAllAsync(filter);
                if (infos.Count > 0)
                {
                    Debug.Log("Found " + infos.Count + " Devices");
                    foreach (DeviceInformation info in infos)
                    {
                        string deviceID = info.Id;
                        Debug.Log("Device Name: " + info.Name);
                        try
                        {
                            BluetoothLEDevice device = await BluetoothLEDevice.FromIdAsync(deviceID);
                            GattDevice d             = GattDevice.Create(device);
                            returnDevices.Add(d);
                        }
                        catch { }
                    }
                }

                OnDevicesAcquired?.Invoke(returnDevices);
            }
                                                                    );
        }
Ejemplo n.º 2
0
        private async static void ConnectedDevicesWithServiceGuidAsync(Guid guid)
        {
            List <GattDevice>           returnDevices = new List <GattDevice>();
            DeviceInformationCollection infos         = await DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(guid));

            if (infos.Count > 0)
            {
                Debug.Log("Found " + infos.Count + " Devices");
                foreach (DeviceInformation info in infos)
                {
                    string deviceID = info.Id;
                    Debug.Log("Device Name: " + info.Name);
                    try
                    {
                        BluetoothLEDevice device = await BluetoothLEDevice.FromIdAsync(deviceID);

                        GattDevice d = GattDevice.Create(device);
                        returnDevices.Add(d);
                    }
                    catch { }
                }
            }

            OnDevicesAcquired?.Invoke(returnDevices);
        }
Ejemplo n.º 3
0
        private async static void DevicesWithConnectionStatusAsync(bool Connected)
        {
            List <GattDevice>           returnDevices = new List <GattDevice>();
            string                      filter        = BluetoothLEDevice.GetDeviceSelectorFromConnectionStatus(Connected ? BluetoothConnectionStatus.Connected : BluetoothConnectionStatus.Disconnected);
            DeviceInformationCollection infos         = await DeviceInformation.FindAllAsync(filter);

            if (infos.Count > 0)
            {
                Debug.Log("Found " + infos.Count + " Devices");
                foreach (DeviceInformation info in infos)
                {
                    string deviceID = info.Id;
                    Debug.Log("Device Name: " + info.Name);
                    try
                    {
                        BluetoothLEDevice device = await BluetoothLEDevice.FromIdAsync(deviceID);

                        GattDevice d = GattDevice.Create(device);
                        returnDevices.Add(d);
                    }
                    catch { }
                }
            }

            OnDevicesAcquired?.Invoke(returnDevices);

            /*Debug.Log("Found " + infos.Count + " Devices");
             * foreach (DeviceInformation info in infos)
             * {
             *  Debug.Log("Device Name: " + info.Name);
             * }*/
        }