Table of Contents

Class BaseBluetoothRemoteDescriptor

Namespace
Bluetooth.Core.Scanning
Assembly
Bluetooth.Core.Scanning.dll

Interface representing a Bluetooth descriptor, providing properties and methods for interacting with it. Descriptors provide additional information about a characteristic (e.g., Client Characteristic Configuration Descriptor).

public abstract class BaseBluetoothRemoteDescriptor : BaseBindableObject, IBluetoothRemoteDescriptor, INotifyPropertyChanged, IAsyncDisposable
Inheritance
BaseBluetoothRemoteDescriptor
Implements
Derived
Inherited Members

Constructors

BaseBluetoothRemoteDescriptor(IBluetoothRemoteCharacteristic, BluetoothRemoteDescriptorFactorySpec, ILogger<IBluetoothRemoteDescriptor>?)

Initializes a new instance using a factory spec.

protected BaseBluetoothRemoteDescriptor(IBluetoothRemoteCharacteristic parentCharacteristic, IBluetoothRemoteDescriptorFactory.BluetoothRemoteDescriptorFactorySpec spec, ILogger<IBluetoothRemoteDescriptor>? logger = null)

Parameters

parentCharacteristic IBluetoothRemoteCharacteristic

The Bluetooth characteristic associated with this descriptor.

spec IBluetoothRemoteDescriptorFactory.BluetoothRemoteDescriptorFactorySpec

The factory spec containing descriptor information.

logger ILogger<IBluetoothRemoteDescriptor>

The logger instance to use for logging (optional).

BaseBluetoothRemoteDescriptor(IBluetoothRemoteCharacteristic, Guid, IBluetoothNameProvider?, ILogger<IBluetoothRemoteDescriptor>?)

Initializes a new instance of the BaseBluetoothRemoteDescriptor class.

protected BaseBluetoothRemoteDescriptor(IBluetoothRemoteCharacteristic parentCharacteristic, Guid id, IBluetoothNameProvider? nameProvider = null, ILogger<IBluetoothRemoteDescriptor>? logger = null)

Parameters

parentCharacteristic IBluetoothRemoteCharacteristic

The Bluetooth characteristic associated with this descriptor.

id Guid

The unique identifier (UUID) of the descriptor.

nameProvider IBluetoothNameProvider

An optional provider for descriptor names, used to resolve the name based on the ID.

logger ILogger<IBluetoothRemoteDescriptor>

The logger instance to use for logging (optional).

Exceptions

ArgumentNullException

Thrown when parentCharacteristic is null.

Properties

CanRead

Gets a value indicating whether the descriptor can be read.

public bool CanRead { get; }

Property Value

bool

CanWrite

Gets a value indicating whether the descriptor can be written to.

public bool CanWrite { get; }

Property Value

bool

Characteristic

Gets the Bluetooth characteristic associated with this descriptor.

public IBluetoothRemoteCharacteristic Characteristic { get; }

Property Value

IBluetoothRemoteCharacteristic

Id

Gets the unique identifier of the descriptor. This is typically a UUID that identifies the type of descriptor (e.g., Client Characteristic Configuration Descriptor has a well-known UUID).

public Guid Id { get; }

Property Value

Guid

IsReadingValue

Gets a value indicating whether a read value operation is currently in progress.

public bool IsReadingValue { get; }

Property Value

bool

IsWritingValue

Gets a value indicating whether a write value operation is currently in progress.

public bool IsWritingValue { get; }

Property Value

bool

Name

The name of the Bluetooth descriptor. This is typically used for debugging and logging purposes, and may not be available for all descriptor. If the descriptor is not recognized, this will default to "Unknown Descriptor".

public string Name { get; }

Property Value

string

Value

Gets the value of the descriptor as a read-only memory segment. Useful for asynchronous operations.

public ReadOnlyMemory<byte> Value { get; protected set; }

Property Value

ReadOnlyMemory<byte>

ValueSpan

Gets the value of the descriptor as a read-only span. Useful for high-performance scenarios.

public ReadOnlySpan<byte> ValueSpan { get; }

Property Value

ReadOnlySpan<byte>

Methods

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

DisposeAsyncCore()

Performs the core disposal logic for the descriptor.

protected virtual ValueTask DisposeAsyncCore()

Returns

ValueTask

NativeCanRead()

Platform-specific implementation to determine if the descriptor can be read.

protected abstract bool NativeCanRead()

Returns

bool

NativeCanWrite()

Platform-specific implementation to determine if the descriptor can be written.

protected abstract bool NativeCanWrite()

Returns

bool

NativeReadValueAsync()

Platform-specific implementation to read the descriptor's value.

protected abstract ValueTask NativeReadValueAsync()

Returns

ValueTask

NativeWriteValueAsync(ReadOnlyMemory<byte>)

Platform-specific implementation to write the descriptor's value.

protected abstract ValueTask NativeWriteValueAsync(ReadOnlyMemory<byte> value)

Parameters

value ReadOnlyMemory<byte>

Returns

ValueTask

OnReadValueFailed(Exception)

Called when reading the descriptor's value fails.

protected void OnReadValueFailed(Exception e)

Parameters

e Exception

OnReadValueSucceeded(ReadOnlyMemory<byte>)

Called when reading the descriptor's value succeeds.

protected void OnReadValueSucceeded(ReadOnlyMemory<byte> value)

Parameters

value ReadOnlyMemory<byte>

OnValueUpdated(ReadOnlyMemory<byte>, ReadOnlyMemory<byte>)

Raises the ValueUpdated event.

protected void OnValueUpdated(ReadOnlyMemory<byte> newValue, ReadOnlyMemory<byte> oldValue)

Parameters

newValue ReadOnlyMemory<byte>

The new value of the descriptor.

oldValue ReadOnlyMemory<byte>

The previous value of the descriptor.

OnWriteValueFailed(Exception)

Called when writing the descriptor's value fails.

protected void OnWriteValueFailed(Exception e)

Parameters

e Exception

OnWriteValueSucceeded()

Called when writing the descriptor's value succeeds.

protected void OnWriteValueSucceeded()

ReadValueAsync(bool, TimeSpan?, CancellationToken)

Reads the value of the descriptor asynchronously.

public ValueTask<ReadOnlyMemory<byte>> ReadValueAsync(bool skipIfPreviouslyRead = false, TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

skipIfPreviouslyRead bool

If true, skips reading if the value was previously read.

timeout TimeSpan?

The timeout for this operation

cancellationToken CancellationToken

A cancellation token to cancel this operation.

Returns

ValueTask<ReadOnlyMemory<byte>>

A task that represents the asynchronous read operation. The task result contains the value read.

Exceptions

DeviceNotConnectedException

Thrown when the device is not connected.

DescriptorCantReadException

Thrown when the descriptor doesn't support read operations.

DescriptorException

Thrown when the read operation fails.

TimeoutException

Thrown when the operation times out.

OperationCanceledException

Thrown when the operation is cancelled.

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

WaitForValueChangeAsync(Func<ReadOnlyMemory<byte>, bool>?, TimeSpan?, CancellationToken)

Waits for the value of the descriptor to change asynchronously.

public ValueTask<ReadOnlyMemory<byte>> WaitForValueChangeAsync(Func<ReadOnlyMemory<byte>, bool>? valueFilter = null, TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

valueFilter Func<ReadOnlyMemory<byte>, bool>

An optional filter function to apply to the value changes. If provided, the task completes only when the filter returns true.

timeout TimeSpan?

The timeout for this operation

cancellationToken CancellationToken

A cancellation token to cancel this operation.

Returns

ValueTask<ReadOnlyMemory<byte>>

A task that represents the asynchronous operation. The task result contains the new value of the descriptor.

WriteValueAsync(ReadOnlyMemory<byte>, bool, TimeSpan?, CancellationToken)

Writes a value to the descriptor asynchronously.

public ValueTask WriteValueAsync(ReadOnlyMemory<byte> value, bool skipIfOldValueMatchesNewValue = false, TimeSpan? timeout = null, CancellationToken cancellationToken = default)

Parameters

value ReadOnlyMemory<byte>

The value to write.

skipIfOldValueMatchesNewValue bool

If true, skips writing if the old value matches the new value.

timeout TimeSpan?

The timeout for this operation

cancellationToken CancellationToken

A cancellation token to cancel this operation.

Returns

ValueTask

A task that represents the asynchronous write operation.

Exceptions

ArgumentNullException

Thrown when value is null.

DeviceNotConnectedException

Thrown when the device is not connected.

DescriptorCantWriteException

Thrown when the descriptor doesn't support write operations.

DescriptorException

Thrown when the write operation fails.

TimeoutException

Thrown when the operation times out.

OperationCanceledException

Thrown when the operation is cancelled.

Events

ValueUpdated

Event raised when the value of the descriptor is updated, only triggered when IsListening is true.

public event EventHandler<ValueUpdatedEventArgs>? ValueUpdated

Event Type

EventHandler<ValueUpdatedEventArgs>