Example #1
0
        /// <summary>
        /// Initialize the list of all characteristics in this service.
        /// </summary>
        public void InitializeCharacteristics()
        {
            // Don't need to initialize multiple times.
            if (CharacteristicModels.Count > 0)
            {
                return;
            }

            // Get characteristics.
            try
            {
                IReadOnlyList <GattCharacteristic> characteristics = _service.GetAllCharacteristics();
                foreach (GattCharacteristic characteristic in characteristics)
                {
                    BECharacteristicModel characteristicM = new BECharacteristicModel();
                    characteristicM.Initialize(this, characteristic);
                    CharacteristicModels.Add(characteristicM);
                }
            }
            catch (Exception ex)
            {
                // GetAllCharacteristics can fail with E_ACCESS_DENIED if another app is holding a
                // reference to the BTLE service.  It can be an active background task, or in the
                // backstack.
                Utilities.OnExceptionWithMessage(ex, "This exception may be encountered if a another app holds a reference to the BTLE service.");
            }
        }
Example #2
0
        /// <summary>
        ///     Initialize the list of all characteristics in this service.
        /// </summary>
        public void InitializeCharacteristics()
        {
            // Don't need to initialize multiple times.
            if (CharacteristicModels != null && CharacteristicModels.Count > 0)
            {
                return;
            }

            // Get characteristics.
            try
            {
                if (CharacteristicModels == null)
                {
                    CharacteristicModels = new List <BECharacteristicModel>();
                }

                var characteristics = _service.GetAllCharacteristics();
                foreach (var characteristic in characteristics)
                {
                    var characteristicM = new BECharacteristicModel();
                    characteristicM.Initialize(this, characteristic);
                    CharacteristicModels.Add(characteristicM);
                }
            }
            catch (Exception ex)
            {
                // GetAllCharacteristics can fail with E_ACCESS_DENIED if another app is holding a
                // reference to the BTLE service.  It can be an active background task, or in the
                // backstack.
                // Utilities.OnExceptionWithMessage(ex, "This exception may be encountered if a another app holds a reference to the BTLE service.");
                Debug.WriteLine(
                    "This exception may be encountered if a another app holds a reference to the BTLE service. {0}",
                    ex.Message);
            }
        }