X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=blobdiff_plain;f=src%2Fhardware%2Frigol-ds%2Fprotocol.c;h=05aaf113f02b0d6f4ecd0e4b1b2b67f90a5f47f8;hp=35d7b43457443a550991e1d81dd147b67915937d;hb=73c575cf9e4b82770d8a6f7c916903e54e9fe7e7;hpb=16e96ca3af93c7b8dc84a924b8404d578771560c diff --git a/src/hardware/rigol-ds/protocol.c b/src/hardware/rigol-ds/protocol.c index 35d7b434..05aaf113 100644 --- a/src/hardware/rigol-ds/protocol.c +++ b/src/hardware/rigol-ds/protocol.c @@ -106,7 +106,7 @@ static void rigol_ds_set_wait_event(struct dev_context *devc, enum wait_events e */ static int rigol_ds_event_wait(const struct sr_dev_inst *sdi, char status1, char status2) { - char *buf; + char *buf, c; struct dev_context *devc; time_t start; @@ -133,7 +133,9 @@ static int rigol_ds_event_wait(const struct sr_dev_inst *sdi, char status1, char if (sr_scpi_get_string(sdi->conn, ":TRIG:STAT?", &buf) != SR_OK) return SR_ERR; - } while (buf[0] == status1 || buf[0] == status2); + c = buf[0]; + g_free(buf); + } while (c == status1 || c == status2); devc->wait_status = 2; } @@ -146,7 +148,9 @@ static int rigol_ds_event_wait(const struct sr_dev_inst *sdi, char status1, char if (sr_scpi_get_string(sdi->conn, ":TRIG:STAT?", &buf) != SR_OK) return SR_ERR; - } while (buf[0] != status1 && buf[0] != status2); + c = buf[0]; + g_free(buf); + } while (c != status1 && c != status2); rigol_ds_set_wait_event(devc, WAIT_NONE); } @@ -263,10 +267,10 @@ static int rigol_ds_check_stop(const struct sr_dev_inst *sdi) /* Wait for enough data becoming available in scope output buffer */ static int rigol_ds_block_wait(const struct sr_dev_inst *sdi) { - char *buf; + char *buf, c; struct dev_context *devc; time_t start; - int len; + int len, ret; if (!(devc = sdi->priv)) return SR_ERR; @@ -292,10 +296,12 @@ static int rigol_ds_block_wait(const struct sr_dev_inst *sdi) /* "READ,nnnn" (still working) or "IDLE,nnnn" (finished) */ if (sr_scpi_get_string(sdi->conn, ":WAV:STAT?", &buf) != SR_OK) return SR_ERR; - - if (parse_int(buf + 5, &len) != SR_OK) + ret = parse_int(buf + 5, &len); + c = buf[0]; + g_free(buf); + if (ret != SR_OK) return SR_ERR; - } while (buf[0] == 'R' && len < (1000 * 1000)); + } while (c == 'R' && len < (1000 * 1000)); } rigol_ds_set_wait_event(devc, WAIT_NONE); @@ -334,6 +340,7 @@ SR_PRIV int rigol_ds_capture_start(const struct sr_dev_inst *sdi) gchar *trig_mode; unsigned int num_channels, i, j; int buffer_samples; + int ret; if (!(devc = sdi->priv)) return SR_ERR; @@ -366,7 +373,9 @@ SR_PRIV int rigol_ds_capture_start(const struct sr_dev_inst *sdi) return SR_ERR; if (sr_scpi_get_string(sdi->conn, ":TRIG:MODE?", &trig_mode) != SR_OK) return SR_ERR; - if (rigol_ds_config_set(sdi, ":TRIG:%s:SWE SING", trig_mode) != SR_OK) + ret = rigol_ds_config_set(sdi, ":TRIG:%s:SWE SING", trig_mode); + g_free(trig_mode); + if (ret != SR_OK) return SR_ERR; if (rigol_ds_config_set(sdi, ":RUN") != SR_OK) return SR_ERR; @@ -691,16 +700,17 @@ SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data) sr_dev_acquisition_stop(sdi); return TRUE; } - /* At slow timebases in live capture the DS2072 - * sometimes returns "short" data blocks, with + /* At slow timebases in live capture the DS2072 and + * DS1054Z sometimes return "short" data blocks, with * apparently no way to get the rest of the data. - * Discard these, the complete data block will - * appear eventually. + * Discard these, the complete data block will appear + * eventually. */ if (devc->data_source == DATA_SOURCE_LIVE && (unsigned)len < expected_data_bytes) { - sr_dbg("Discarding short data block"); + sr_dbg("Discarding short data block: got %d/%d bytes\n", len, (int)expected_data_bytes); sr_scpi_read_data(scpi, (char *)devc->buffer, len + 1); + devc->num_header_bytes = 0; return TRUE; } devc->num_block_bytes = len; @@ -904,7 +914,21 @@ SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst *sdi) /* Probe attenuation. */ for (i = 0; i < devc->model->analog_channels; i++) { cmd = g_strdup_printf(":CHAN%d:PROB?", i + 1); - res = sr_scpi_get_float(sdi->conn, cmd, &devc->attenuation[i]); + + /* DSO1000B series prints an X after the probe factor, so + * we get a string and check for that instead of only handling + * floats. */ + char *response; + res = sr_scpi_get_string(sdi->conn, cmd, &response); + if (res != SR_OK) + return SR_ERR; + + int len = strlen(response); + if (response[len-1] == 'X') + response[len-1] = 0; + + res = sr_atof_ascii(response, &devc->attenuation[i]); + g_free(response); g_free(cmd); if (res != SR_OK) return SR_ERR; @@ -920,6 +944,8 @@ SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst *sdi) /* Coupling. */ for (i = 0; i < devc->model->analog_channels; i++) { cmd = g_strdup_printf(":CHAN%d:COUP?", i + 1); + g_free(devc->coupling[i]); + devc->coupling[i] = NULL; res = sr_scpi_get_string(sdi->conn, cmd, &devc->coupling[i]); g_free(cmd); if (res != SR_OK) @@ -930,6 +956,8 @@ SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst *sdi) sr_dbg("CH%d %s", i + 1, devc->coupling[i]); /* Trigger source. */ + g_free(devc->trigger_source); + devc->trigger_source = NULL; if (sr_scpi_get_string(sdi->conn, ":TRIG:EDGE:SOUR?", &devc->trigger_source) != SR_OK) return SR_ERR; sr_dbg("Current trigger source %s", devc->trigger_source); @@ -941,6 +969,8 @@ SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst *sdi) sr_dbg("Current horizontal trigger position %g", devc->horiz_triggerpos); /* Trigger slope. */ + g_free(devc->trigger_slope); + devc->trigger_slope = NULL; if (sr_scpi_get_string(sdi->conn, ":TRIG:EDGE:SLOP?", &devc->trigger_slope) != SR_OK) return SR_ERR; sr_dbg("Current trigger slope %s", devc->trigger_slope);