readValue method

Future<ByteData> readValue()

Read the value of the descriptor.

This will also set value with the same value as returned by the Future.

  • May throw SecurityError if the descriptor is blocked from reading 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.

Implementation

Future<ByteData> readValue() async {
  try {
    return await _descriptor.readValue();
  } 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");
    }
    rethrow;
  }
}