コード例 #1
0
        /// <summary>
        /// Creates and initialises a new GattDevice
        /// </summary>
        /// <param name="device"></param>
        /// <returns></returns>
        internal static GattDevice Create(BluetoothLEDevice device)
        {
            GattDevice d = new GattDevice(device);

            d.services = GattService.GetServices(d);
            return(d);
        }
コード例 #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);
        }
コード例 #3
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);
            }
                                                                    );
        }
コード例 #4
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);
             * }*/
        }
コード例 #5
0
        /// <summary>
        /// Creates a list of services given a GattDevice
        /// </summary>
        /// <param name="device"></param>
        /// <returns></returns>
        public static List <GattService> GetServices(GattDevice device)
        {
            List <GattService> returnList = new List <GattService>();

            foreach (GattDeviceService service in device.device.GattServices)
            {
                GattService s = GattService.Create(service);
                returnList.Add(s);
            }

            return(returnList);
        }
コード例 #6
0
        private static async void GetDeviceAsync(GattInformation info)
        {
            GattDevice dev = null;

            // We must update the collection on the UI thread
            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                BluetoothLEDevice device = await BluetoothLEDevice.FromIdAsync(info.Id);
                dev = GattDevice.Create(device);
            });

            if (dev != null)
            {
                OnDeviceCreated?.Invoke(dev);
            }
        }