X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fcommon%2Fserial.c;h=220533a41b753f9d6844801574963b1d95f4f657;hb=2244356d1069c5b13fe3b728a421750900deaafe;hp=bc837a3841f29e575eefa9ab5490cfe4ecf0475b;hpb=b87f8504dc82eab0155263887662ac14c252414d;p=libsigrok.git diff --git a/hardware/common/serial.c b/hardware/common/serial.c index bc837a38..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; @@ -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; }