checkStatus method
Asks the printer whether it can take job: writes the status query
and waits up to 1500ms for the first reply bytes. Connects if needed
(the connection is left open). PrinterReadiness.unknown on any error
or when the printer does not answer.
Implementation
Future<PrinterReadiness> checkStatus(List<int> job) async {
final q = PrinterStatusQuery.forJob(job);
try {
await connect();
final s = socket;
if (s == null || _socketError != null) return PrinterReadiness.unknown;
_rx.clear();
final waiter = Completer<void>();
_rxWaiter = waiter;
s.add(q.query);
await s.flush();
if (_rx.isEmpty) {
await waiter.future
.timeout(const Duration(milliseconds: 1500), onTimeout: () {});
}
_rxWaiter = null;
if (_rx.isEmpty) return PrinterReadiness.unknown;
final reply = Uint8List.fromList(_rx);
_rx.clear();
return q.parse(reply);
} catch (_) {
_rxWaiter = null;
return PrinterReadiness.unknown;
}
}