transferOut method

  1. @override
Future<int> transferOut(
  1. Uint8List data,
  2. int timeout
)
override

Implementation

@override
Future<int> transferOut(Uint8List data, int timeout) async {
  try {
    final activeDevice = _activeDevice;
    if (activeDevice == null) {
      throw Exception('No active device; use open() first');
    }
    final device = activeDevice.device;
    final endpointNumber = activeDevice.outEndpointNumber;

    if (!device.opened) {
      await device.open();
    }

    final result = await device.transferOut(endpointNumber, data);
    return result.bytesWritten;
  } catch (e) {
    debugPrint('Error in transferOut: $e');
    if (e.toString().contains('InvalidStateError')) {
      await _reopenDevice();
      return transferOut(data, timeout);
    }
    return -1;
  }
}