Ejemplo n.º 1
0
        public async Task ReadUTF8Value()
        {
            try
            {
                if ((_characteristic.CharacteristicProperties & GattCharacteristicProperties.Read) != 0)
                {
                    // Determine if we want to read the actual or cached values
                    var cacheMode = BluetoothCacheMode.Cached;
                    if (!GlobalSettings.UseCachedMode && ServiceM.DeviceM.Connected)
                    {
                        cacheMode = BluetoothCacheMode.Uncached;
                    }

                    // Get some basic device info.
                    var readResult = await _characteristic.ReadValueAsync(cacheMode);

                    var gattStatus = readResult.Status;
                    if (gattStatus == GattCommunicationStatus.Success)
                    {
                        CharacteristicValue = BasicParsers.ParseUtf8(readResult.Value);
                    }
                }
            }
            catch (Exception e)
            {
                // Utilities.OnExceptionWithMessage(e, "Failed to read characteristic value");
                Debug.WriteLine("Failed to read characteristic value {0}", e.Message);
            }
        }