From cda85239dc8586e7cdd018c0beec489c1309e213 Mon Sep 17 00:00:00 2001 From: fengyuewuhen <825027047@qq.com> Date: Tue, 18 Jan 2022 03:58:46 +0800 Subject: [PATCH] For some unknown reason, every printing file need sleep a little time on first transmit (#431) serial: Add a 10-msec sleep and at the end add a tcdrain() For some unknown reason, every printing file need sleep a little time to make sure the serial printer receive data is right. --- backend/serial.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/backend/serial.c b/backend/serial.c index 71627fbc1..6c54655c5 100644 --- a/backend/serial.c +++ b/backend/serial.c @@ -108,6 +108,7 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */ #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET) struct sigaction action; /* Actions for POSIX signals */ #endif /* HAVE_SIGACTION && !HAVE_SIGSET */ + char print_sleep = 0; /* Print first sleep flag on every transmit */ /* @@ -652,6 +653,16 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */ } } + /* + * on every transmit need to wait a little + * even though the DSR is OK for some unknown reasons. + */ + if (print_sleep == 0) + { + usleep(10000); + print_sleep = 1; + } + if ((bytes = write(device_fd, print_ptr, print_bytes)) < 0) { /* @@ -674,6 +685,7 @@ main(int argc, /* I - Number of command-line arguments (6 or 7) */ } else { + tcdrain(device_fd); fprintf(stderr, "DEBUG: Wrote %d bytes.\n", (int)bytes); print_bytes -= bytes;