Exemplo n.º 1
0
        public async partial Task WriteAsync(ReadOnlyMemory <byte> value, bool withResponse)
        {
            var buffer = value.ToArray().AsBuffer();
            var option = withResponse ? GattWriteOption.WriteWithResponse : GattWriteOption.WriteWithoutResponse;
            var result = await characteristic.WriteValueWithResultAsync(buffer, option);

            Platform.AssertStatus(result.Status, result.ProtocolError);
        }
Exemplo n.º 2
0
        async Task _WriteValueAsync(ReadOnlyMemory <byte> data, GattWriteOption option)
        {
            // REVISIT: copying everything twice
            var writer = new DataWriter();

            writer.WriteBytes(data.ToArray());
            switch (option)
            {
            case GattWriteOption.WriteWithResponse:
                var result = await characteristic.WriteValueWithResultAsync(writer.DetachBuffer());

                switch (result.Status)
                {
                case Win.GattCommunicationStatus.Success:
                    return;

                default:
                    throw new Exception();
                }

            case GattWriteOption.WriteWithoutResponse:
                var result2 = await characteristic.WriteValueAsync(writer.DetachBuffer(), Win.GattWriteOption.WriteWithoutResponse);

                switch (result2)
                {
                case Win.GattCommunicationStatus.Success:
                    return;

                default:
                    throw new Exception();
                }

            default:
                throw new ArgumentException("Invalid write option", nameof(option));
            }
        }