X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Frigol-ds%2Fapi.c;h=8af03eb6970626e3482d3ef1d2b51cc7fafe179a;hb=7cf1a98d733b97656ef1b28259d5cd2b4190a104;hp=e0f4eaea2a388f1a7eb2deaad60abbf3125ab223;hpb=3086efdd73885820da142ce8c36053bbc3cf0e5f;p=libsigrok.git diff --git a/hardware/rigol-ds/api.c b/hardware/rigol-ds/api.c index e0f4eaea..8af03eb6 100644 --- a/hardware/rigol-ds/api.c +++ b/hardware/rigol-ds/api.c @@ -3,6 +3,7 @@ * * Copyright (C) 2012 Martin Ling * Copyright (C) 2013 Bert Vermeulen + * Copyright (C) 2013 Mathias Grimmberger * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,11 +28,9 @@ #include "libsigrok-internal.h" #include "protocol.h" -#define NUM_TIMEBASE 12 -#define NUM_VDIV 8 - static const int32_t hwopts[] = { SR_CONF_CONN, + SR_CONF_SERIALCOMM }; static const int32_t hwcaps[] = { @@ -47,6 +46,7 @@ static const int32_t analog_hwcaps[] = { SR_CONF_NUM_VDIV, SR_CONF_VDIV, SR_CONF_COUPLING, + SR_CONF_DATA_SOURCE, }; static const uint64_t timebases[][2] = { @@ -85,10 +85,17 @@ static const uint64_t timebases[][2] = { { 10, 1 }, { 20, 1 }, { 50, 1 }, + { 100, 1 }, + { 200, 1 }, + { 500, 1 }, + /* { 1000, 1 }, Confuses other code? */ }; static const uint64_t vdivs[][2] = { + /* microvolts */ + { 500, 1000000 }, /* millivolts */ + { 1, 1000 }, { 2, 1000 }, { 5, 1000 }, { 10, 1000 }, @@ -104,6 +111,9 @@ static const uint64_t vdivs[][2] = { { 10, 1 }, }; +#define NUM_TIMEBASE ARRAY_SIZE(timebases) +#define NUM_VDIV ARRAY_SIZE(vdivs) + static const char *trigger_sources[] = { "CH1", "CH2", @@ -133,13 +143,37 @@ static const char *coupling[] = { "GND", }; -static const char *supported_models[] = { - "DS1052E", - "DS1102E", - "DS1152E", - "DS1052D", - "DS1102D", - "DS1152D", +/* Do not change the order of entries */ +static const char *data_sources[] = { + "Live", + "Memory", + "Segmented", +}; + +/* + * name, series, protocol flavor, min timebase, max timebase, min vdiv, + * digital channels, number of horizontal divs + */ +static const struct rigol_ds_model supported_models[] = { + {"DS1052E", RIGOL_DS1000, PROTOCOL_LEGACY, {5, 1000000000}, {50, 1}, {2, 1000}, false, 12}, + {"DS1102E", RIGOL_DS1000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, false, 12}, + {"DS1152E", RIGOL_DS1000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, false, 12}, + {"DS1052D", RIGOL_DS1000, PROTOCOL_LEGACY, {5, 1000000000}, {50, 1}, {2, 1000}, true, 12}, + {"DS1102D", RIGOL_DS1000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, true, 12}, + {"DS1152D", RIGOL_DS1000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, true, 12}, + {"DS2072", RIGOL_DS2000, PROTOCOL_IEEE488_2, {5, 1000000000}, {500, 1}, {500, 1000000}, false, 14}, + {"DS2102", RIGOL_DS2000, PROTOCOL_IEEE488_2, {5, 1000000000}, {500, 1}, {500, 1000000}, false, 14}, + {"DS2202", RIGOL_DS2000, PROTOCOL_IEEE488_2, {2, 1000000000}, {500, 1}, {500, 1000000}, false, 14}, + {"VS5022", RIGOL_VS5000, PROTOCOL_LEGACY, {20, 1000000000}, {50, 1}, {2, 1000}, false, 14}, + {"VS5022D", RIGOL_VS5000, PROTOCOL_LEGACY, {20, 1000000000}, {50, 1}, {2, 1000}, true, 14}, + {"VS5042", RIGOL_VS5000, PROTOCOL_LEGACY, {10, 1000000000}, {50, 1}, {2, 1000}, false, 14}, + {"VS5042D", RIGOL_VS5000, PROTOCOL_LEGACY, {10, 1000000000}, {50, 1}, {2, 1000}, true, 14}, + {"VS5062", RIGOL_VS5000, PROTOCOL_LEGACY, {5, 1000000000}, {50, 1}, {2, 1000}, false, 14}, + {"VS5062D", RIGOL_VS5000, PROTOCOL_LEGACY, {5, 1000000000}, {50, 1}, {2, 1000}, true, 14}, + {"VS5102", RIGOL_VS5000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, false, 14}, + {"VS5102D", RIGOL_VS5000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, true, 14}, + {"VS5202", RIGOL_VS5000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, false, 14}, + {"VS5202D", RIGOL_VS5000, PROTOCOL_LEGACY, {2, 1000000000}, {50, 1}, {2, 1000}, true, 14}, }; SR_PRIV struct sr_dev_driver rigol_ds_driver_info; @@ -150,6 +184,8 @@ static void clear_helper(void *priv) struct dev_context *devc; devc = priv; + g_free(devc->data); + g_free(devc->buffer); g_free(devc->coupling[0]); g_free(devc->coupling[1]); g_free(devc->trigger_source); @@ -167,12 +203,13 @@ static int dev_clear(void) static int set_cfg(const struct sr_dev_inst *sdi, const char *format, ...) { va_list args; - char buf[256]; + int ret; va_start(args, format); - vsnprintf(buf, 255, format, args); + ret = sr_scpi_send_variadic(sdi->conn, format, args); va_end(args); - if (rigol_ds_send(sdi, buf) != SR_OK) + + if (ret != SR_OK) return SR_ERR; /* When setting a bunch of parameters in a row, the DS1052E scrambles @@ -188,81 +225,91 @@ static int init(struct sr_context *sr_ctx) return std_init(sr_ctx, di, LOG_PREFIX); } -static int probe_port(const char *port, GSList **devices) +static int probe_port(const char *resource, const char *serialcomm, GSList **devices) { struct dev_context *devc; struct sr_dev_inst *sdi; - struct sr_serial_dev_inst *serial; + const char *usbtmc_prefix = "/dev/usbtmc"; + const char *tcp_prefix = "tcp/"; + gchar **tokens, *address, *port; + struct sr_scpi_dev_inst *scpi; + struct sr_scpi_hw_info *hw_info; struct sr_probe *probe; unsigned int i; - int len, num_tokens; - gboolean matched, has_digital; - const char *manufacturer, *model, *version; - char buf[256]; - gchar **tokens, *channel_name; + const struct rigol_ds_model *model = NULL; + gchar *channel_name; *devices = NULL; - if (!(serial = sr_serial_dev_inst_new(port, NULL))) - return SR_ERR_MALLOC; - if (serial_open(serial, SERIAL_RDWR) != SR_OK) - return SR_ERR; - len = serial_write(serial, "*IDN?", 5); - len = serial_read(serial, buf, sizeof(buf)); - if (serial_close(serial) != SR_OK) - return SR_ERR; - - sr_serial_dev_inst_free(serial); - - if (len == 0) - return SR_ERR_NA; - - buf[len] = 0; - tokens = g_strsplit(buf, ",", 0); - sr_dbg("response: %s [%s]", port, buf); - - for (num_tokens = 0; tokens[num_tokens] != NULL; num_tokens++); - - if (num_tokens < 4) { + if (strncmp(resource, usbtmc_prefix, strlen(usbtmc_prefix)) == 0) { + sr_dbg("Opening USBTMC device %s.", resource); + if (!(scpi = scpi_usbtmc_dev_inst_new(resource))) + return SR_ERR_MALLOC; + } else if (strncmp(resource, tcp_prefix, strlen(tcp_prefix)) == 0) { + sr_dbg("Opening TCP connection %s.", resource); + tokens = g_strsplit(resource + strlen(tcp_prefix), "/", 0); + address = tokens[0]; + port = tokens[1]; + if (!address || !port || tokens[2]) { + sr_err("Invalid parameters."); + g_strfreev(tokens); + return SR_ERR_ARG; + } + scpi = scpi_tcp_dev_inst_new(address, port); g_strfreev(tokens); - return SR_ERR_NA; + if (!scpi) + return SR_ERR_MALLOC; + } else { + sr_dbg("Opening serial device %s.", resource); + if (!(scpi = scpi_serial_dev_inst_new(resource, serialcomm))) + return SR_ERR_MALLOC; } - manufacturer = tokens[0]; - model = tokens[1]; - version = tokens[3]; + if (sr_scpi_open(scpi) != SR_OK) { + sr_scpi_free(scpi); + return SR_ERR; + }; - if (strcmp(manufacturer, "Rigol Technologies")) { - g_strfreev(tokens); + if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) { + sr_info("Couldn't get IDN response."); + sr_scpi_close(scpi); + sr_scpi_free(scpi); + return SR_ERR; + } + + if (strcasecmp(hw_info->manufacturer, "Rigol Technologies")) { + sr_scpi_hw_info_free(hw_info); + sr_scpi_free(scpi); return SR_ERR_NA; } - matched = has_digital = FALSE; for (i = 0; i < ARRAY_SIZE(supported_models); i++) { - if (!strcmp(model, supported_models[i])) { - matched = TRUE; - has_digital = g_str_has_suffix(model, "D"); + if (!strcmp(hw_info->model, supported_models[i].name)) { + model = &supported_models[i]; break; } } - if (!matched || !(sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, - manufacturer, model, version))) { - g_strfreev(tokens); + if (!model || !(sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, + hw_info->manufacturer, hw_info->model, + hw_info->firmware_version))) { + sr_scpi_hw_info_free(hw_info); + sr_scpi_free(scpi); return SR_ERR_NA; } - g_strfreev(tokens); + sr_scpi_hw_info_free(hw_info); + + sdi->conn = scpi; - if (!(sdi->conn = sr_serial_dev_inst_new(port, NULL))) - return SR_ERR_MALLOC; sdi->driver = di; - sdi->inst_type = SR_INST_SERIAL; + sdi->inst_type = SR_INST_SCPI; if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) return SR_ERR_MALLOC; + devc->limit_frames = 0; - devc->has_digital = has_digital; + devc->model = model; for (i = 0; i < 2; i++) { channel_name = (i == 0 ? "CH1" : "CH2"); @@ -275,7 +322,7 @@ static int probe_port(const char *port, GSList **devices) &devc->analog_groups[i]); } - if (devc->has_digital) { + if (devc->model->has_digital) { for (i = 0; i < 16; i++) { if (!(channel_name = g_strdup_printf("D%d", i))) return SR_ERR_MALLOC; @@ -286,11 +333,33 @@ static int probe_port(const char *port, GSList **devices) sdi->probes = g_slist_append(sdi->probes, probe); devc->digital_group.probes = g_slist_append( devc->digital_group.probes, probe); - devc->digital_group.name = "LA"; - sdi->probe_groups = g_slist_append(sdi->probe_groups, - &devc->digital_group); } + devc->digital_group.name = "LA"; + sdi->probe_groups = g_slist_append(sdi->probe_groups, + &devc->digital_group); + } + + for (i = 0; i < NUM_TIMEBASE; i++) { + if (!memcmp(&devc->model->min_timebase, &timebases[i], sizeof(uint64_t[2]))) + devc->timebases = &timebases[i]; + if (!memcmp(&devc->model->max_timebase, &timebases[i], sizeof(uint64_t[2]))) + devc->num_timebases = &timebases[i] - devc->timebases + 1; } + + for (i = 0; i < NUM_VDIV; i++) { + if (!memcmp(&devc->model->min_vdiv, &vdivs[i], sizeof(uint64_t[2]))) { + devc->vdivs = &vdivs[i]; + devc->num_vdivs = NUM_VDIV - (&vdivs[i] - &vdivs[0]); + } + } + + if (!(devc->buffer = g_try_malloc(ACQ_BUFFER_SIZE))) + return SR_ERR_MALLOC; + if (!(devc->data = g_try_malloc(ACQ_BUFFER_SIZE * sizeof(float)))) + return SR_ERR_MALLOC; + + devc->data_source = DATA_SOURCE_LIVE; + sdi->priv = devc; *devices = g_slist_append(NULL, sdi); @@ -307,21 +376,30 @@ static GSList *scan(GSList *options) int ret; const gchar *dev_name; gchar *port = NULL; + gchar *serialcomm = NULL; drvc = di->priv; for (l = options; l; l = l->next) { src = l->data; - if (src->key == SR_CONF_CONN) { + switch (src->key) { + case SR_CONF_CONN: port = (char *)g_variant_get_string(src->data, NULL); break; + case SR_CONF_SERIALCOMM: + serialcomm = (char *)g_variant_get_string(src->data, NULL); + break; } } devices = NULL; if (port) { - if (probe_port(port, &devices) == SR_ERR_MALLOC) + if (probe_port(port, serialcomm, &devices) == SR_ERR_MALLOC) { + g_free(port); + if (serialcomm) + g_free(serialcomm); return NULL; + } } else { if (!(dir = g_dir_open("/sys/class/usbmisc/", 0, NULL))) if (!(dir = g_dir_open("/sys/class/usb/", 0, NULL))) @@ -330,8 +408,10 @@ static GSList *scan(GSList *options) if (strncmp(dev_name, "usbtmc", 6)) continue; port = g_strconcat("/dev/", dev_name, NULL); - ret = probe_port(port, &devices); + ret = probe_port(port, serialcomm, &devices); g_free(port); + if (serialcomm) + g_free(serialcomm); if (ret == SR_ERR_MALLOC) { g_dir_close(dir); return NULL; @@ -354,8 +434,9 @@ static GSList *dev_list(void) static int dev_open(struct sr_dev_inst *sdi) { + struct sr_scpi_dev_inst *scpi = sdi->conn; - if (serial_open(sdi->conn, SERIAL_RDWR) != SR_OK) + if (sr_scpi_open(scpi) < 0) return SR_ERR; if (rigol_ds_get_dev_cfg(sdi) != SR_OK) @@ -368,11 +449,13 @@ static int dev_open(struct sr_dev_inst *sdi) static int dev_close(struct sr_dev_inst *sdi) { - struct sr_serial_dev_inst *serial; + struct sr_scpi_dev_inst *scpi; + + scpi = sdi->conn; - serial = sdi->conn; - if (serial && serial->fd != -1) { - serial_close(serial); + if (scpi) { + if (sr_scpi_close(scpi) < 0) + return SR_ERR; sdi->status = SR_ST_INACTIVE; } @@ -404,7 +487,7 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, switch (id) { case SR_CONF_NUM_TIMEBASE: - *data = g_variant_new_int32(NUM_TIMEBASE); + *data = g_variant_new_int32(devc->num_timebases); break; case SR_CONF_NUM_VDIV: if (!probe_group) { @@ -413,11 +496,19 @@ static int config_get(int id, GVariant **data, const struct sr_dev_inst *sdi, } for (i = 0; i < 2; i++) { if (probe_group == &devc->analog_groups[i]) { - *data = g_variant_new_int32(NUM_VDIV); + *data = g_variant_new_int32(devc->num_vdivs); return SR_OK; } } return SR_ERR_NA; + case SR_CONF_DATA_SOURCE: + if (devc->data_source == DATA_SOURCE_LIVE) + *data = g_variant_new_string("Live"); + else if (devc->data_source == DATA_SOURCE_MEMORY) + *data = g_variant_new_string("Memory"); + else + *data = g_variant_new_string("Segmented"); + break; default: return SR_ERR_NA; } @@ -470,19 +561,19 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, devc->horiz_triggerpos = t_dbl; /* We have the trigger offset as a percentage of the frame, but * need to express this in seconds. */ - t_dbl = -(devc->horiz_triggerpos - 0.5) * devc->timebase * NUM_TIMEBASE; + t_dbl = -(devc->horiz_triggerpos - 0.5) * devc->timebase * devc->num_timebases; ret = set_cfg(sdi, ":TIM:OFFS %.6f", t_dbl); break; case SR_CONF_TIMEBASE: g_variant_get(data, "(tt)", &p, &q); - for (i = 0; i < ARRAY_SIZE(timebases); i++) { - if (timebases[i][0] == p && timebases[i][1] == q) { + for (i = 0; i < devc->num_timebases; i++) { + if (devc->timebases[i][0] == p && devc->timebases[i][1] == q) { devc->timebase = (float)p / q; ret = set_cfg(sdi, ":TIM:SCAL %.9f", devc->timebase); break; } } - if (i == ARRAY_SIZE(timebases)) + if (i == devc->num_timebases) ret = SR_ERR_ARG; break; case SR_CONF_TRIGGER_SOURCE: @@ -545,6 +636,18 @@ static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, } } return SR_ERR_NA; + case SR_CONF_DATA_SOURCE: + tmp_str = g_variant_get_string(data, NULL); + if (!strcmp(tmp_str, "Live")) + devc->data_source = DATA_SOURCE_LIVE; + else if (!strcmp(tmp_str, "Memory")) + devc->data_source = DATA_SOURCE_MEMORY; + else if (devc->model->protocol == PROTOCOL_IEEE488_2 + && !strcmp(tmp_str, "Segmented")) + devc->data_source = DATA_SOURCE_SEGMENTED; + else + return SR_ERR; + break; default: ret = SR_ERR_NA; break; @@ -559,7 +662,10 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, GVariant *tuple, *rational[2]; GVariantBuilder gvb; unsigned int i; - struct dev_context *devc; + struct dev_context *devc = NULL; + + if (sdi) + devc = sdi->priv; if (key == SR_CONF_SCAN_OPTIONS) { *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, @@ -614,32 +720,51 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, *data = g_variant_new_strv(coupling, ARRAY_SIZE(coupling)); break; case SR_CONF_VDIV: + if (!devc) + /* Can't know this until we have the exact model. */ + return SR_ERR_ARG; if (!probe_group) { sr_err("No probe group specified."); return SR_ERR_PROBE_GROUP; } g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); - for (i = 0; i < ARRAY_SIZE(vdivs); i++) { - rational[0] = g_variant_new_uint64(vdivs[i][0]); - rational[1] = g_variant_new_uint64(vdivs[i][1]); + for (i = 0; i < devc->num_vdivs; i++) { + rational[0] = g_variant_new_uint64(devc->vdivs[i][0]); + rational[1] = g_variant_new_uint64(devc->vdivs[i][1]); tuple = g_variant_new_tuple(rational, 2); g_variant_builder_add_value(&gvb, tuple); } *data = g_variant_builder_end(&gvb); break; case SR_CONF_TIMEBASE: + if (!devc) + /* Can't know this until we have the exact model. */ + return SR_ERR_ARG; g_variant_builder_init(&gvb, G_VARIANT_TYPE_ARRAY); - for (i = 0; i < ARRAY_SIZE(timebases); i++) { - rational[0] = g_variant_new_uint64(timebases[i][0]); - rational[1] = g_variant_new_uint64(timebases[i][1]); + for (i = 0; i < devc->num_timebases; i++) { + rational[0] = g_variant_new_uint64(devc->timebases[i][0]); + rational[1] = g_variant_new_uint64(devc->timebases[i][1]); tuple = g_variant_new_tuple(rational, 2); g_variant_builder_add_value(&gvb, tuple); } *data = g_variant_builder_end(&gvb); break; case SR_CONF_TRIGGER_SOURCE: + if (!devc) + /* Can't know this until we have the exact model. */ + return SR_ERR_ARG; *data = g_variant_new_strv(trigger_sources, - devc->has_digital ? ARRAY_SIZE(trigger_sources) : 4); + devc->model->has_digital ? ARRAY_SIZE(trigger_sources) : 4); + break; + case SR_CONF_DATA_SOURCE: + if (!devc) + /* Can't know this until we have the exact model. */ + return SR_ERR_ARG; + /* This needs tweaking by series/model! */ + if (devc->model->series == RIGOL_DS2000) + *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources)); + else + *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources) - 1); break; default: return SR_ERR_NA; @@ -650,7 +775,7 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) { - struct sr_serial_dev_inst *serial; + struct sr_scpi_dev_inst *scpi; struct dev_context *devc; struct sr_probe *probe; GSList *l; @@ -659,9 +784,22 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) if (sdi->status != SR_ST_ACTIVE) return SR_ERR_DEV_CLOSED; - serial = sdi->conn; + scpi = sdi->conn; devc = sdi->priv; + if (devc->data_source == DATA_SOURCE_LIVE) { + if (sr_scpi_send(sdi->conn, ":RUN") != SR_OK) + return SR_ERR; + } else if (devc->data_source == DATA_SOURCE_MEMORY) { + if (devc->model->series != RIGOL_DS2000) { + sr_err("Data source 'Memory' not supported for this device"); + return SR_ERR; + } + } else if (devc->data_source == DATA_SOURCE_SEGMENTED) { + sr_err("Data source 'Segmented' not yet supported"); + return SR_ERR; + } + for (l = sdi->probes; l; l = l->next) { probe = l->data; sr_dbg("handling probe %s", probe->name); @@ -673,7 +811,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) /* Enabled channel is currently disabled, or vice versa. */ sprintf(cmd, ":CHAN%d:DISP %s", probe->index + 1, probe->enabled ? "ON" : "OFF"); - if (rigol_ds_send(sdi, cmd) != SR_OK) + if (sr_scpi_send(sdi->conn, cmd) != SR_OK) return SR_ERR; } } else if (probe->type == SR_PROBE_LOGIC) { @@ -684,7 +822,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) /* Enabled channel is currently disabled, or vice versa. */ sprintf(cmd, ":DIG%d:TURN %s", probe->index, probe->enabled ? "ON" : "OFF"); - if (rigol_ds_send(sdi, cmd) != SR_OK) + if (sr_scpi_send(sdi->conn, cmd) != SR_OK) return SR_ERR; } } @@ -692,32 +830,58 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi, void *cb_data) if (!devc->enabled_analog_probes && !devc->enabled_digital_probes) return SR_ERR; - sr_source_add(serial->fd, G_IO_IN, 50, rigol_ds_receive, (void *)sdi); + sr_scpi_source_add(scpi, G_IO_IN, 50, rigol_ds_receive, (void *)sdi); /* Send header packet to the session bus. */ std_session_send_df_header(cb_data, LOG_PREFIX); - /* Fetch the first frame. */ - if (devc->enabled_analog_probes) { - devc->channel_frame = devc->enabled_analog_probes->data; - if (rigol_ds_send(sdi, ":WAV:DATA? CHAN%d", - devc->channel_frame->index + 1) != SR_OK) - return SR_ERR; + if (devc->model->protocol == PROTOCOL_LEGACY) { + /* Fetch the first frame. */ + if (devc->enabled_analog_probes) { + devc->analog_frame_size = DS1000_ANALOG_LIVE_WAVEFORM_SIZE; + devc->channel_frame = devc->enabled_analog_probes->data; + if (sr_scpi_send(sdi->conn, ":WAV:DATA? CHAN%d", + devc->channel_frame->index + 1) != SR_OK) + return SR_ERR; + } else { + devc->channel_frame = devc->enabled_digital_probes->data; + if (sr_scpi_send(sdi->conn, ":WAV:DATA? DIG") != SR_OK) + return SR_ERR; + } + + devc->num_frame_bytes = 0; } else { - devc->channel_frame = devc->enabled_digital_probes->data; - if (rigol_ds_send(sdi, ":WAV:DATA? DIG") != SR_OK) - return SR_ERR; + if (devc->enabled_analog_probes) { + if (devc->data_source == DATA_SOURCE_MEMORY) + { + if (g_slist_length(devc->enabled_analog_probes) == 1) + devc->analog_frame_size = DS2000_ANALOG_MEM_WAVEFORM_SIZE_1C; + else + devc->analog_frame_size = DS2000_ANALOG_MEM_WAVEFORM_SIZE_2C; + /* Apparently for the DS2000 the memory + * depth can only be set in Running state - + * this matches the behaviour of the UI. */ + if (sr_scpi_send(sdi->conn, ":RUN") != SR_OK) + return SR_ERR; + if (sr_scpi_send(sdi->conn, "ACQ:MDEP %d", devc->analog_frame_size) != SR_OK) + return SR_ERR; + if (sr_scpi_send(sdi->conn, ":STOP") != SR_OK) + return SR_ERR; + } else + devc->analog_frame_size = DS2000_ANALOG_LIVE_WAVEFORM_SIZE; + devc->channel_frame = devc->enabled_analog_probes->data; + if (rigol_ds_capture_start(sdi) != SR_OK) + return SR_ERR; + } } - devc->num_frame_bytes = 0; - return SR_OK; } static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { struct dev_context *devc; - struct sr_serial_dev_inst *serial; + struct sr_scpi_dev_inst *scpi; (void)cb_data; @@ -732,8 +896,8 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) g_slist_free(devc->enabled_digital_probes); devc->enabled_analog_probes = NULL; devc->enabled_digital_probes = NULL; - serial = sdi->conn; - sr_source_remove(serial->fd); + scpi = sdi->conn; + sr_scpi_source_remove(scpi); return SR_OK; }