]> sigrok.org Git - libsigrok.git/blobdiff - hardware/common/serial.c
comment fix
[libsigrok.git] / hardware / common / serial.c
index c39b2ca57cbec99c9f330b57aa2834ab071ab8d5..220533a41b753f9d6844801574963b1d95f4f657 100644 (file)
@@ -126,6 +126,8 @@ SR_PRIV int serial_open(const char *pathname, int flags)
                 */
                sr_dbg("Error opening serial port '%s': %s.", pathname,
                       strerror(errno));
+       } else {
+               sr_dbg("Opened serial port '%s' as FD %d.", pathname, fd);
        }
 
        return fd;
@@ -195,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;
 
@@ -210,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
@@ -228,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;
 
@@ -247,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;
@@ -601,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;
@@ -619,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;
                        }
@@ -630,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;
 }