From: Bert Vermeulen Date: Sun, 7 Apr 2013 23:12:42 +0000 (+0200) Subject: rigol-ds1xx2: better debugging X-Git-Tag: dsupstream~173 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=a3df166f02201abe253b6fd4ee416394dace9e5e;p=libsigrok.git rigol-ds1xx2: better debugging --- diff --git a/hardware/rigol-ds1xx2/api.c b/hardware/rigol-ds1xx2/api.c index 0bc2a23c..d8561a76 100644 --- a/hardware/rigol-ds1xx2/api.c +++ b/hardware/rigol-ds1xx2/api.c @@ -351,12 +351,12 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) break; case SR_CONF_TRIGGER_SLOPE: tmp_u64 = g_variant_get_uint64(data); - rigol_ds1xx2_send_data(devc->fd, ":TRIG:EDGE:SLOP %s\n", + rigol_ds1xx2_send_data(devc->fd, ":TRIG:EDGE:SLOP %s", tmp_u64 ? "POS" : "NEG"); break; case SR_CONF_HORIZ_TRIGGERPOS: tmp_double = g_variant_get_double(data); - rigol_ds1xx2_send_data(devc->fd, ":TIM:OFFS %.9f\n", tmp_double); + rigol_ds1xx2_send_data(devc->fd, ":TIM:OFFS %.9f", tmp_double); break; case SR_CONF_TIMEBASE: g_variant_get(data, "(tt)", &p, &q); @@ -368,7 +368,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) } } if (tmp_int >= 0) - rigol_ds1xx2_send_data(devc->fd, ":TIM:SCAL %.9f\n", + rigol_ds1xx2_send_data(devc->fd, ":TIM:SCAL %.9f", (float)timebases[i][0] / timebases[i][1]); break; case SR_CONF_TRIGGER_SOURCE: @@ -385,7 +385,7 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) ret = SR_ERR_ARG; break; } - rigol_ds1xx2_send_data(devc->fd, ":TRIG:EDGE:SOUR %s\n", channel); + rigol_ds1xx2_send_data(devc->fd, ":TRIG:EDGE:SOUR %s", channel); break; case SR_CONF_VDIV: g_variant_get(data, "(tt)", &p, &q); @@ -394,9 +394,9 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) if (vdivs[i][0] != p || vdivs[i][1] != q) continue; devc->scale = (float)vdivs[i][0] / vdivs[i][1]; - rigol_ds1xx2_send_data(devc->fd, ":CHAN0:SCAL %.3f\n", + rigol_ds1xx2_send_data(devc->fd, ":CHAN0:SCAL %.3f", devc->scale); - rigol_ds1xx2_send_data(devc->fd, ":CHAN1:SCAL %.3f\n", + rigol_ds1xx2_send_data(devc->fd, ":CHAN1:SCAL %.3f", devc->scale); break; } @@ -408,9 +408,9 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi) tmp_str = g_variant_get_string(data, NULL); for (i = 0; i < ARRAY_SIZE(coupling); i++) { if (!strcmp(tmp_str, coupling[i])) { - rigol_ds1xx2_send_data(devc->fd, ":CHAN0:COUP %s\n", + rigol_ds1xx2_send_data(devc->fd, ":CHAN0:COUP %s", coupling[i]); - rigol_ds1xx2_send_data(devc->fd, ":CHAN1:COUP %s\n", + rigol_ds1xx2_send_data(devc->fd, ":CHAN1:COUP %s", coupling[i]); break; } @@ -494,17 +494,17 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, /* Hardcoded to CH1 only. */ devc->enabled_probes = g_slist_append(NULL, sdi->probes->data); - rigol_ds1xx2_send_data(devc->fd, ":CHAN1:SCAL?\n"); + rigol_ds1xx2_send_data(devc->fd, ":CHAN1:SCAL?"); len = read(devc->fd, buf, sizeof(buf)); buf[len] = 0; devc->scale = atof(buf); sr_dbg("Scale is %.3f.", devc->scale); - rigol_ds1xx2_send_data(devc->fd, ":CHAN1:OFFS?\n"); + rigol_ds1xx2_send_data(devc->fd, ":CHAN1:OFFS?"); len = read(devc->fd, buf, sizeof(buf)); buf[len] = 0; devc->offset = atof(buf); sr_dbg("Offset is %.6f.", devc->offset); - rigol_ds1xx2_send_data(devc->fd, ":WAV:DATA?\n"); + rigol_ds1xx2_send_data(devc->fd, ":WAV:DATA?"); return SR_OK; } diff --git a/hardware/rigol-ds1xx2/protocol.c b/hardware/rigol-ds1xx2/protocol.c index 161e73bb..ecc517e2 100644 --- a/hardware/rigol-ds1xx2/protocol.c +++ b/hardware/rigol-ds1xx2/protocol.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include "libsigrok.h" #include "libsigrok-internal.h" @@ -74,7 +75,7 @@ SR_PRIV int rigol_ds1xx2_receive_data(int fd, int revents, void *cb_data) if (++devc->num_frames == devc->limit_frames) sdi->driver->dev_acquisition_stop(sdi, cb_data); else - rigol_ds1xx2_send_data(fd, ":WAV:DATA?\n"); + rigol_ds1xx2_send_data(fd, ":WAV:DATA?"); } } @@ -85,13 +86,22 @@ SR_PRIV int rigol_ds1xx2_send_data(int fd, const char *format, ...) { va_list args; char buf[256]; - int len; + int len, out, ret; va_start(args, format); len = vsprintf(buf, format, args); va_end(args); - len = write(fd, buf, len); - sr_dbg("Sent '%s'.", buf); + strcat(buf, "\n"); + len++; + out = write(fd, buf, len); + buf[len - 1] = '\0'; + if (out != len) { + sr_dbg("Only sent %d/%d bytes of '%s'.", out, len, buf); + ret = SR_ERR; + } else { + sr_dbg("Sent '%s'.", buf); + ret = SR_OK; + } - return len; + return ret; }