diff --git a/include/tabby/printer.h b/include/tabby/printer.h index 6fab3bf..dfe319c 100644 --- a/include/tabby/printer.h +++ b/include/tabby/printer.h @@ -5,7 +5,6 @@ #define TABBY_PRINTER_SYNC_2 0x33 #define TABBY_PRINTER_DEVICE_ID 0x81 -#define TABBY_PRINTER_RETRY_COUNT 5 #define TABBY_PRINTER_PACKET_MAX_SIZE 640 diff --git a/src/printer.c b/src/printer.c index d33d394..29f612f 100644 --- a/src/printer.c +++ b/src/printer.c @@ -107,33 +107,24 @@ int tabby_printer_packet_send(int fd, void *body, tabby_printer_response *response) { uint16_t sum = checksum(header, body); - int tries = TABBY_PRINTER_RETRY_COUNT; - do { - if (tries-- == 0) { - errno = EIO; + if (write(fd, header, sizeof(*header)) < 0) { + goto error_io; + } + if (header->size) { + if (write(fd, body, header->size) < 0) { goto error_io; } + } - if (write(fd, header, sizeof(*header)) < 0) { - goto error_io; - } + if (write(fd, &sum, sizeof(sum)) < 0) { + goto error_io; + } - if (header->size) { - if (write(fd, body, header->size) < 0) { - goto error_io; - } - } - - if (write(fd, &sum, sizeof(sum)) < 0) { - goto error_io; - } - - if (read(fd, response, sizeof(*response)) < 0) { - goto error_io; - } - } while (resend(response)); + if (read(fd, response, sizeof(*response)) < 0) { + goto error_io; + } return 0; @@ -213,6 +204,13 @@ int tabby_printer_send_sheet(int fd, void *data, goto error_packet_send; } + if (resend(¤t)) { + tabby_printer_init(fd, ¤t); + i = -1; + + continue; + } + offset += TABBY_PRINTER_BAND_SIZE; }