]> sigrok.org Git - libsigrok.git/blobdiff - hardware/rigol-ds/protocol.c
rigol-ds: fix waveform reception on DS2000 series
[libsigrok.git] / hardware / rigol-ds / protocol.c
index 4dec85b4fdcc90e26734c1f5fb83cd5dc2555c0a..eefed0745b8f3e9276c71c7c93ac56458f70cddf 100644 (file)
@@ -368,7 +368,7 @@ static int rigol_ds_read_header(struct sr_scpi_dev_inst *scpi)
        int len, tmp;
 
        /* Read the hashsign and length digit. */
-       tmp = sr_scpi_read(scpi, start, 2);
+       tmp = sr_scpi_read_data(scpi, start, 2);
        start[2] = '\0';
        if (tmp != 2)
        {
@@ -383,7 +383,7 @@ static int rigol_ds_read_header(struct sr_scpi_dev_inst *scpi)
        len = atoi(start + 1);
 
        /* Read the data length. */
-       tmp = sr_scpi_read(scpi, length, len);
+       tmp = sr_scpi_read_data(scpi, length, len);
        length[len] = '\0';
        if (tmp != len)
        {
@@ -457,11 +457,17 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
 
                probe = devc->channel_entry->data;
                
+               if (devc->num_block_bytes == 0 &&
+                   devc->model->protocol == PROTOCOL_IEEE488_2) {
+                               if (sr_scpi_send(sdi->conn, ":WAV:DATA?") != SR_OK)
+                                       return TRUE;
+               }
+
                if (devc->num_block_bytes == 0) {
+                       if (sr_scpi_read_begin(scpi) != SR_OK)
+                               return TRUE;
                        if (devc->model->protocol == PROTOCOL_IEEE488_2) {
                                sr_dbg("New block header expected");
-                               if (sr_scpi_send(sdi->conn, ":WAV:DATA?") != SR_OK)
-                                       return TRUE;
                                len = rigol_ds_read_header(scpi);
                                if (len == -1)
                                        return TRUE;
@@ -474,7 +480,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
                                if (devc->data_source == DATA_SOURCE_LIVE
                                                && (unsigned)len < devc->num_frame_samples) {
                                        sr_dbg("Discarding short data block");
-                                       sr_scpi_read(scpi, (char *)devc->buffer, len + 1);
+                                       sr_scpi_read_data(scpi, (char *)devc->buffer, len + 1);
                                        return TRUE;
                                }
                                devc->num_block_bytes = len;
@@ -489,7 +495,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
                }
 
                len = devc->num_block_bytes - devc->num_block_read;
-               len = sr_scpi_read(scpi, (char *)devc->buffer,
+               len = sr_scpi_read_data(scpi, (char *)devc->buffer,
                                len < ACQ_BUFFER_SIZE ? len : ACQ_BUFFER_SIZE);
 
                sr_dbg("Received %d bytes.", len);
@@ -538,7 +544,7 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data)
                        if (devc->model->protocol == PROTOCOL_IEEE488_2) {
                                /* Discard the terminating linefeed and prepare for
                                   possible next block */
-                               sr_scpi_read(scpi, (char *)devc->buffer, 1);
+                               sr_scpi_read_data(scpi, (char *)devc->buffer, 1);
                                devc->num_block_bytes = 0;
                                if (devc->data_source != DATA_SOURCE_LIVE)
                                        rigol_ds_set_wait_event(devc, WAIT_BLOCK);
@@ -613,10 +619,7 @@ static int get_cfg(const struct sr_dev_inst *sdi, char *cmd, char *reply, size_t
        struct sr_scpi_dev_inst *scpi = sdi->conn;
        char *response;
 
-       if (sr_scpi_send(scpi, cmd) != SR_OK)
-               return SR_ERR;
-
-       if (sr_scpi_receive(scpi, &response) != SR_OK)
+       if (sr_scpi_get_string(scpi, cmd, &response) != SR_OK)
                return SR_ERR;
 
        g_strlcpy(reply, response, maxlen);