X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fcommon%2Fserial.c;h=220533a41b753f9d6844801574963b1d95f4f657;hb=2244356d1069c5b13fe3b728a421750900deaafe;hp=5a1d21af90c4cbebc9a593847f7b0fe1634c51e2;hpb=83e3c368c67d6bbc86015fc47a7f7e39160b3baa;p=libsigrok.git diff --git a/hardware/common/serial.c b/hardware/common/serial.c index 5a1d21af..220533a4 100644 --- a/hardware/common/serial.c +++ b/hardware/common/serial.c @@ -197,8 +197,6 @@ SR_PRIV int serial_flush(int fd) */ SR_PRIV int serial_write(int fd, const void *buf, size_t count) { - sr_spew("FD %d: Writing %d bytes.", fd, count); - #ifdef _WIN32 DWORD tmp = 0; @@ -212,8 +210,8 @@ SR_PRIV int serial_write(int fd, const void *buf, size_t count) ret = write(fd, buf, count); if (ret < 0) sr_err("FD %d: Write error: %s.", fd, strerror(errno)); - else if ((size_t)ret != count) - sr_spew("FD %d: Only wrote %d/%d bytes.", fd, ret, count); + else + sr_spew("FD %d: Wrote %d/%d bytes.", fd, ret, count); return ret; #endif @@ -230,8 +228,6 @@ SR_PRIV int serial_write(int fd, const void *buf, size_t count) */ SR_PRIV int serial_read(int fd, void *buf, size_t count) { - sr_spew("FD %d: Reading %d bytes.", fd, count); - #ifdef _WIN32 DWORD tmp = 0; @@ -249,8 +245,8 @@ SR_PRIV int serial_read(int fd, void *buf, size_t count) * "Resource temporarily unavailable" messages. */ sr_spew("FD %d: Read error: %s.", fd, strerror(errno)); - } else if ((size_t)ret != count) { - sr_spew("FD %d: Only read %d/%d bytes.", fd, ret, count); + } else { + sr_spew("FD %d: Read %d/%d bytes.", fd, ret, count); } return ret; @@ -603,9 +599,9 @@ SR_PRIV int serial_set_paramstr(int fd, const char *paramstr) } SR_PRIV int serial_readline(int fd, char **buf, int *buflen, - uint64_t timeout_ms) + gint64 timeout_ms) { - uint64_t start; + gint64 start; int maxlen, len; timeout_ms *= 1000; @@ -621,8 +617,9 @@ SR_PRIV int serial_readline(int fd, char **buf, int *buflen, if (len > 0) { *buflen += len; *(*buf + *buflen) = '\0'; - if (*buflen > 0 && *(*buf + *buflen - 1) == '\r') { - /* Strip LF and terminate. */ + if (*buflen > 0 && (*(*buf + *buflen - 1) == '\r' + || *(*buf + *buflen - 1) == '\n')) { + /* Strip CR/LF and terminate. */ *(*buf + --*buflen) = '\0'; break; } @@ -632,7 +629,8 @@ SR_PRIV int serial_readline(int fd, char **buf, int *buflen, break; g_usleep(2000); } - sr_dbg("Received %d: '%s'.", *buflen, *buf); + if (*buflen) + sr_dbg("Received %d: '%s'.", *buflen, *buf); return SR_OK; }