transferOut method
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;
}
}