public static IGattCharacteristicWrapper WithWriteValueAsyncResult(
            this IGattCharacteristicWrapper characteristic,
            GattCommunicationStatus status)
        {
            _ = characteristic.WriteValueAsync(Arg.Any <IBuffer> ( ))
                .Returns(Task.FromResult(status));

            return(characteristic);
        }
        private async Task <bool> SetHexValueAsync(string hex)
        {
            var bytes = DataConverter.HexStringToByteArray(hex);

            var writer = new DataWriter
            {
                ByteOrder = ByteOrder.LittleEndian
            };

            writer.WriteBytes(bytes);

            var writeSuccessful = await _hubCharacteristic.WriteValueAsync(writer.DetachBuffer());

            return(writeSuccessful);
        }
Ejemplo n.º 3
0
        public async Task <bool> TryWritableAuxiliariesValueAsync(
            [NotNull] IGattCharacteristicWrapper characteristic,
            [NotNull] IBuffer buffer)
        {
            Guard.ArgumentNotNull(characteristic,
                                  nameof(characteristic));
            Guard.ArgumentNotNull(buffer,
                                  nameof(buffer));

            if (SupportsWritableAuxiliaries(characteristic))
            {
                Log.Information($"GattCharacteristic '{characteristic.Uuid}' " +
                                "doesn't support 'Write/WritableAuxiliaries/" +
                                "WriteWithoutResponse'");

                return(false);
            }

            var status = await characteristic.WriteValueAsync(buffer);

            return(status == GattCommunicationStatus.Success);
        }