예제 #1
0
        async Task <byte[]> DoGetValue()
        {
            var result = await _characteristic.ReadValueAsync(Windows.Devices.Bluetooth.BluetoothCacheMode.Cached).AsTask().ConfigureAwait(false);

            if (result.Status == Uap.GattCommunicationStatus.Success)
            {
                return(result.Value.ToArray());
            }

            return(null);
        }
예제 #2
0
        byte[] PlatformGetValue()
        {
            var result = _characteristic.ReadValueAsync(Windows.Devices.Bluetooth.BluetoothCacheMode.Cached).GetResults();

            if (result.Status == Uap.GattCommunicationStatus.Success)
            {
                return(result.Value.ToArray());
            }

            return(null);
        }
예제 #3
0
        public async partial Task <ReadOnlyMemory <byte> > ReadAsync()
        {
            var result = await characteristic.ReadValueAsync(BluetoothCacheMode.Uncached);

            Platform.AssertStatus(result.Status, result.ProtocolError);
            return(result.Value.ToArray());
        }
예제 #4
0
        private async void CharacteristicReadButton_Click()
        {
            // BT_Code: Read the actual value from the device by using Uncached.
            GattReadResult result = await selectedCharacteristic.ReadValueAsync(BluetoothCacheMode.Uncached);

            if (result.Status == GattCommunicationStatus.Success)
            {
                string formattedResult = FormatValueByPresentation(result.Value, presentationFormat);
                rootPage.NotifyUser($"Read result: {formattedResult}", NotifyType.StatusMessage);
            }
            else
            {
                rootPage.NotifyUser($"Read failed: {result.Status}", NotifyType.ErrorMessage);
            }
        }
예제 #5
0
        async Task <Memory <byte> > _ReadValueAsync()
        {
            var result = await characteristic.ReadValueAsync();

            switch (result.Status)
            {
            case Win.GattCommunicationStatus.Success:
                var data   = new byte[result.Value.Length];
                var reader = DataReader.FromBuffer(result.Value);
                reader.ReadBytes(data);
                return((Memory <byte>)data);

            case Win.GattCommunicationStatus.AccessDenied:
                throw new AccessViolationException("Access denied");

            case Win.GattCommunicationStatus.ProtocolError:
                throw new FormatException($"Protocol error: {result.ProtocolError}");

            case Win.GattCommunicationStatus.Unreachable:
                // TODO: more specific exception
                throw new Exception("Unreachable");
            }
            throw new ArgumentException("Unknown status");
        }