writeValue method

Future<void> writeValue(
  1. Uint8List data
)

Write a new value to the descriptor.

data Data may not be larger than 512 bytes.

  • May throw SecurityError if the descriptor is blocked from writing using the blocklist.

  • May throw NetworkError if the device is not connected or if there is an error with the communication.

  • May throw StateError if the descriptor is null.

  • May throw StateError if the input data is larger than 512 bytes. TODO: use better error.

Implementation

Future<void> writeValue(final Uint8List data) async {
  try {
    _descriptor.writeValue(data);
  } catch (e) {
    final error = e.toString().trim();
    if (error.startsWith("NotSupportedError")) {
      throw NotSupportedError(uuid);
    } else if (error.startsWith("NetworkError")) {
      throw NetworkError.withUUid(uuid);
    } else if (error.startsWith("SecurityError")) {
      throw SecurityError(uuid, error);
    } else if (error.startsWith("InvalidStateError")) {
      throw StateError("Descriptor is null");
    } else if (error.startsWith("InvalidModificationError")) {
      throw StateError("Input data was larger than 512 bytes");
    }
    rethrow;
  }
}