From 41c4af0d0dae2310b4d4cee74b3c427d8144e897 Mon Sep 17 00:00:00 2001 From: Kevin Bradenstein Date: Sat, 5 Sep 2026 10:07:01 +0200 Subject: [PATCH] allow a printer to raise the default status timeout The PT-E560BT stays busy about 2.2 s after even an 8 mm label, so the 1 second default timeout cannot succeed on a job sent straight after another: printing five chained labels gives a strip carrying three of them. ptouch-print reports the timeout and exits non-zero correctly every time, but no amount of waiting helps when the default is below the printer's fixed overhead. Add a trailing min_timeout to the device table. Every other row keeps its initialiser and gets 0, which resolves to the old default of 1; only the E560BT carries a value. An explicit --timeout always wins. Raising the global default would also be defensible: ptouch_getstatus() returns as soon as the status arrives, measured 0.13 s with --timeout 30 against 0.14 s with --timeout 1, so a higher ceiling costs nothing on a printer that is ready. But that is a judgement about printers I do not have, so this keeps it to the one that was measured. --- include/ptouch.h | 4 ++++ src/libptouch.c | 2 +- src/ptouch-print.c | 10 ++++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/ptouch.h b/include/ptouch.h index bb199be..1e5c21b 100644 --- a/include/ptouch.h +++ b/include/ptouch.h @@ -62,6 +62,10 @@ struct _pt_dev_info { Brother "Software Developer's Manual - Raster Command Reference, PT-P900/P900W/P950NW", section 2.3.5 "Raster line". 0 = centred. */ int pin_offset; + /* Seconds to wait for a status response when the user did not ask for a + particular --timeout. 0 means use the global default; a printer only + needs an entry here if the global default is too short for it. */ + int min_timeout; }; typedef struct _pt_dev_info *pt_dev_info; diff --git a/src/libptouch.c b/src/libptouch.c index 212214b..4847bb9 100644 --- a/src/libptouch.c +++ b/src/libptouch.c @@ -107,7 +107,7 @@ struct _pt_dev_info ptdevs[] = { /* 3,5/6/9/12/18 mm TZe Tapes, 12mm and 18mm tested */ /* 5,2/9/11,2 mm HSe heat shrink tubes not tested, probably requiring extension of struct _pt_tape_info */ {0x04f9, 0x2201, "PT-E310BT", 128, 180, FLAG_P700_INIT|FLAG_USE_INFO_CMD|FLAG_D460BT_MAGIC, 0}, - {0x04f9, 0x2203, "PT-E560BT", 128, 180, FLAG_P700_INIT|FLAG_USE_INFO_CMD|FLAG_D460BT_MAGIC, 0}, + {0x04f9, 0x2203, "PT-E560BT", 128, 180, FLAG_P700_INIT|FLAG_USE_INFO_CMD|FLAG_D460BT_MAGIC, 0, 10}, {0,0,"",0,0,0,0} }; diff --git a/src/ptouch-print.c b/src/ptouch-print.c index 54a4feb..c1dff6e 100644 --- a/src/ptouch-print.c +++ b/src/ptouch-print.c @@ -108,7 +108,7 @@ static struct argp_option options[] = { { "writepng", 'w', "", OPTION_ALIAS, "alias for write-png", 1}, { "force-tape-width", 6, "", 0, "Set tape width in pixels, use together with --writepng without a printer connected", 1}, { "copies", 7, "", 0, "Sets the number of identical prints", 1}, - { "timeout", 8, "", 0, "Set timeout waiting for finishing previous job. Default:1, 0 means infinity", 1}, + { "timeout", 8, "", 0, "Set timeout waiting for finishing previous job. Default:1, or a per-printer minimum where one is known. 0 means infinity", 1}, { 0, 0, 0, 0, "print commands:", 2}, { "image", 'i', "", 0, "Print the given image which must be a 2 color (black/white) png", 2}, @@ -141,7 +141,7 @@ struct arguments arguments = { .forced_tape_width = 0, .save_png = NULL, .verbose = 0, - .timeout = 1 + .timeout = -1 /* -1 = not given; 0 is already "infinity" */ }; job_t *jobs = NULL; @@ -751,6 +751,12 @@ int main(int argc, char *argv[]) if (ptouch_init(ptdev) != 0) { printf(_("ptouch_init() failed\n")); } + /* Resolve the timeout only now, because it can depend on which + printer answered. An explicit --timeout always wins. */ + if (arguments.timeout < 0) { + arguments.timeout = ptdev->devinfo->min_timeout > 0 + ? ptdev->devinfo->min_timeout : 1; + } if (ptouch_getstatus(ptdev, arguments.timeout) != 0) { printf(_("ptouch_getstatus() failed\n")); return 1;