コード例 #1
0
        /// <summary>
        /// Read a value from a GATT characteristic
        /// </summary>
        /// <param name="characteristic">GATT characteristic</param>
        /// <param name="value">Value</param>
        /// <returns>true if the operation succeeded, false otherwise</returns>
        public async Task <bool> ReadValueAsync(BleGattCharacteristic characteristic, BleValue value)
        {
            bool ret = false;

            GattCharacteristic gatt_characteristic = characteristic.Context as GattCharacteristic;
            GattReadResult     result = await gatt_characteristic.ReadValueAsync(BluetoothCacheMode.Uncached);

            if (result.Status == GattCommunicationStatus.Success)
            {
                byte[] val;
                CryptographicBuffer.CopyToByteArray(result.Value, out val);
                value.Value = val;
                ret         = true;
            }

            return(ret);
        }
コード例 #2
0
        /// <summary>
        /// Write a value into a GATT characteristic
        /// </summary>
        /// <param name="characteristic">GATT characteristic</param>
        /// <param name="value">Value</param>
        /// <returns>true if the operation succeeded, false otherwise</returns>
        public async Task <bool> WriteValueAsync(BleGattCharacteristic characteristic, BleValue value)
        {
            bool ret = false;

            GattCharacteristic gatt_characteristic = characteristic.Context as GattCharacteristic;
            IBuffer            buffer = CryptographicBuffer.CreateFromByteArray(value.Value);
            GattWriteResult    result = await gatt_characteristic.WriteValueWithResultAsync(buffer, GattWriteOption.WriteWithResponse);

            if (result.Status == GattCommunicationStatus.Success)
            {
                ret = true;
            }

            return(ret);
        }