connector retry reconnect

This commit is contained in:
2023-11-19 00:37:42 +03:00
parent 63cc7b5575
commit 47ff925859

View File

@@ -63,8 +63,23 @@ public class PrinterConnector implements IPOSListener {
return (int) (inches * this.PRINTER_DPI);
}
public void printBitmap(Bitmap bitmap) {
static final int RETRY_COUNT = 5;
public void printBitmap(Bitmap bitmap) {
if (printer == null) {
this.reconnect();
int iteration = 0;
while (true) {
if (printer != null) break;
if (iteration > RETRY_COUNT) return;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
iteration++;
}
}
Dimensions dimensions = this.config.getDimensions();
int widthInDots = mmToDots(dimensions.getWidth());