]> sigrok.org Git - libsigrok.git/commitdiff
scpi_usbtmc: Improve debugging output.
authorMartin Ling <redacted>
Wed, 22 Jan 2014 04:48:33 +0000 (04:48 +0000)
committerBert Vermeulen <redacted>
Thu, 23 Jan 2014 00:42:33 +0000 (01:42 +0100)
hardware/common/scpi_usbtmc.c

index 3c98c06bc8c87bfa2eeb38cf962f821c271cd675..75fcf3aed2a789d39d8ddf2d2bcd175704f59635 100644 (file)
@@ -119,6 +119,8 @@ static int scpi_usbtmc_read_begin(void *priv)
        uscpi->response_length = len;
        uscpi->response_bytes_read = 0;
 
+       sr_spew("Read %d bytes from device into buffer", len);
+
        return SR_OK;
 }
 
@@ -127,13 +129,18 @@ static int scpi_usbtmc_read_data(void *priv, char *buf, int maxlen)
        struct usbtmc_scpi *uscpi = priv;
        int read_length;
 
-       if (uscpi->response_length == MAX_READ_LENGTH
-           && uscpi->response_bytes_read == uscpi->response_length)
-               if (scpi_usbtmc_read_begin(uscpi) != SR_OK)
-                       return SR_ERR;
+       sr_spew("%d bytes requested", maxlen);
 
-       if (uscpi->response_bytes_read >= uscpi->response_length)
-               return SR_ERR;
+       if (uscpi->response_bytes_read == uscpi->response_length) {
+               sr_spew("Buffer is empty.");
+               if (uscpi->response_length == MAX_READ_LENGTH) {
+                       sr_spew("Previous read was of maximum length, reading again.");
+                       if (scpi_usbtmc_read_begin(uscpi) != SR_OK)
+                               return SR_ERR;
+               } else {
+                       return SR_ERR;
+               }
+       }
 
        read_length = uscpi->response_length - uscpi->response_bytes_read;
 
@@ -144,6 +151,9 @@ static int scpi_usbtmc_read_data(void *priv, char *buf, int maxlen)
 
        uscpi->response_bytes_read += read_length;
 
+       sr_spew("Returned %d bytes from buffer, %d/%d bytes of buffer now read",
+                       read_length, uscpi->response_bytes_read, uscpi->response_length);
+
        return read_length;
 }