readBytes method

  1. @override
Future<Uint8List> readBytes({
  1. required int handleId,
  2. required int maxBytes,
  3. required int timeoutMs,
})
override

Reads up to maxBytes from the bulk-IN endpoint. Returns the actual bytes read (may be 0). Throws UsbTransferTimeoutException on timeout.

Implementation

@override
Future<Uint8List> readBytes({
  required int handleId,
  required int maxBytes,
  required int timeoutMs,
}) async {
  if (readError != null) throw readError!;
  final h = _handles[handleId];
  if (h == null) throw StateError('Invalid handle $handleId');
  if (h.readQueue.isEmpty) return Uint8List(0);
  return h.readQueue.removeFirst();
}