X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Frigol-ds%2Fapi.c;h=aab4730265d892e4d158cf0ed9d233452495567e;hb=HEAD;hp=38b880de2e19927bdc05c15b60fae8a7feb82389;hpb=8cbe5339b1514d600e11f727fa44edd9b0744887;p=libsigrok.git diff --git a/src/hardware/rigol-ds/api.c b/src/hardware/rigol-ds/api.c index 38b880de..6703d1ce 100644 --- a/src/hardware/rigol-ds/api.c +++ b/src/hardware/rigol-ds/api.c @@ -42,7 +42,7 @@ static const uint32_t drvopts[] = { }; static const uint32_t devopts[] = { - SR_CONF_LIMIT_FRAMES | SR_CONF_SET, + SR_CONF_LIMIT_FRAMES | SR_CONF_GET | SR_CONF_SET, SR_CONF_SAMPLERATE | SR_CONF_GET, SR_CONF_TIMEBASE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, SR_CONF_NUM_HDIV | SR_CONF_GET, @@ -273,13 +273,15 @@ static const struct rigol_ds_model supported_models[] = { {SERIES(DS1000Z), "DS1104Z", {5, 1000000000}, CH_INFO(4, false), std_cmd}, {SERIES(DS1000Z), "DS1074Z-S", {5, 1000000000}, CH_INFO(4, false), std_cmd}, {SERIES(DS1000Z), "DS1104Z-S", {5, 1000000000}, CH_INFO(4, false), std_cmd}, - {SERIES(DS1000Z), "DS1074Z Plus", {5, 1000000000}, CH_INFO(4, false), std_cmd}, - {SERIES(DS1000Z), "DS1104Z Plus", {5, 1000000000}, CH_INFO(4, false), std_cmd}, + {SERIES(DS1000Z), "DS1074Z Plus", {5, 1000000000}, CH_INFO(4, true), std_cmd}, + {SERIES(DS1000Z), "DS1104Z Plus", {5, 1000000000}, CH_INFO(4, true), std_cmd}, + {SERIES(DS1000Z), "DS1102Z-E", {2, 1000000000}, CH_INFO(2, false), std_cmd}, {SERIES(DS1000Z), "DS1202Z-E", {2, 1000000000}, CH_INFO(2, false), std_cmd}, {SERIES(DS1000Z), "MSO1074Z", {5, 1000000000}, CH_INFO(4, true), std_cmd}, {SERIES(DS1000Z), "MSO1104Z", {5, 1000000000}, CH_INFO(4, true), std_cmd}, {SERIES(DS1000Z), "MSO1074Z-S", {5, 1000000000}, CH_INFO(4, true), std_cmd}, {SERIES(DS1000Z), "MSO1104Z-S", {5, 1000000000}, CH_INFO(4, true), std_cmd}, + {SERIES(DS4000), "DS4014", {1, 1000000000}, CH_INFO(4, false), std_cmd}, {SERIES(DS4000), "DS4024", {1, 1000000000}, CH_INFO(4, false), std_cmd}, {SERIES(MSO5000), "MSO5072", {1, 1000000000}, CH_INFO(2, true), std_cmd}, {SERIES(MSO5000), "MSO5074", {1, 1000000000}, CH_INFO(4, true), std_cmd}, @@ -293,6 +295,8 @@ static const struct rigol_ds_model supported_models[] = { static struct sr_dev_driver rigol_ds_driver_info; +static int analog_frame_size(const struct sr_dev_inst *); + static void clear_helper(struct dev_context *devc) { unsigned int i; @@ -392,17 +396,13 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) channel_name = g_strdup_printf("CH%d", i + 1); ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_name); - devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group)); - - devc->analog_groups[i]->name = channel_name; + devc->analog_groups[i] = sr_channel_group_new(sdi, + channel_name, NULL); devc->analog_groups[i]->channels = g_slist_append(NULL, ch); - sdi->channel_groups = g_slist_append(sdi->channel_groups, - devc->analog_groups[i]); } if (devc->model->has_digital) { - devc->digital_group = g_malloc0(sizeof(struct sr_channel_group)); - + devc->digital_group = sr_channel_group_new(sdi, "LA", NULL); for (i = 0; i < ARRAY_SIZE(devc->digital_channels); i++) { channel_name = g_strdup_printf("D%d", i); ch = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_name); @@ -410,9 +410,6 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi) devc->digital_group->channels = g_slist_append( devc->digital_group->channels, ch); } - devc->digital_group->name = g_strdup("LA"); - sdi->channel_groups = g_slist_append(sdi->channel_groups, - devc->digital_group); } for (i = 0; i < ARRAY_SIZE(timebases); i++) { @@ -570,6 +567,9 @@ static int config_get(uint32_t key, GVariant **data, else *data = g_variant_new_string("Segmented"); break; + case SR_CONF_LIMIT_FRAMES: + *data = g_variant_new_uint64(devc->limit_frames); + break; case SR_CONF_SAMPLERATE: *data = g_variant_new_uint64(devc->sample_rate); break; @@ -876,9 +876,12 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) gboolean some_digital; GSList *l; char *cmd; + int protocol; + int ret; scpi = sdi->conn; devc = sdi->priv; + protocol = devc->model->series->protocol; devc->num_frames = 0; devc->num_frames_segmented = 0; @@ -902,7 +905,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) /* Only one list entry for older protocols. All channels are * retrieved together when this entry is processed. */ if (ch->enabled && ( - devc->model->series->protocol > PROTOCOL_V3 || + protocol > PROTOCOL_V3 || !some_digital)) devc->enabled_channels = g_slist_append( devc->enabled_channels, ch); @@ -910,8 +913,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) some_digital = TRUE; /* Turn on LA module if currently off. */ if (!devc->la_enabled) { - if (rigol_ds_config_set(sdi, - devc->model->series->protocol >= PROTOCOL_V3 ? + if (rigol_ds_config_set(sdi, protocol >= PROTOCOL_V3 ? ":LA:STAT ON" : ":LA:DISP ON") != SR_OK) return SR_ERR; devc->la_enabled = TRUE; @@ -919,9 +921,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) } if (ch->enabled != devc->digital_channels[ch->index]) { /* Enabled channel is currently disabled, or vice versa. */ - if (devc->model->series->protocol >= PROTOCOL_V5) + if (protocol >= PROTOCOL_V5) cmd = ":LA:DISP D%d,%s"; - else if (devc->model->series->protocol >= PROTOCOL_V3) + else if (protocol >= PROTOCOL_V3) cmd = ":LA:DIG%d:DISP %s"; else cmd = ":DIG%d:TURN %s"; @@ -946,21 +948,34 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) /* Set memory mode. */ if (devc->data_source == DATA_SOURCE_SEGMENTED) { - if (devc->model->series->protocol == PROTOCOL_V4) { + switch (protocol) { + case PROTOCOL_V1: + case PROTOCOL_V2: + /* V1 and V2 do not have segmented data */ + sr_err("Data source 'Segmented' not supported on this model"); + break; + case PROTOCOL_V3: + case PROTOCOL_V4: + { int frames = 0; - /* PROTOCOL_V5 has RECORD:FRAMES?, but this seems to return the - * maximum that should be captured, not the current amount. If - * we can figure out how to get the current number of frames, - * or when we've hit the last one, adding support for this will - * be possible as well. - */ - sr_scpi_get_int(sdi->conn, "FUNC:WREP:FEND?", &frames); + if (sr_scpi_get_int(sdi->conn, + protocol == PROTOCOL_V4 ? "FUNC:WREP:FEND?" : + "FUNC:WREP:FMAX?", &frames) != SR_OK) + return SR_ERR; if (frames <= 0) { sr_err("No segmented data available"); return SR_ERR; } devc->num_frames_segmented = frames; - } else { + break; + } + case PROTOCOL_V5: + /* The frame limit has to be read on the fly, just set up + * reading of the first frame */ + if (rigol_ds_config_set(sdi, "REC:CURR 1") != SR_OK) + return SR_ERR; + break; + default: sr_err("Data source 'Segmented' not yet supported"); return SR_ERR; } @@ -1001,20 +1016,27 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) devc->channel_entry = devc->enabled_channels; - if (devc->data_source == DATA_SOURCE_LIVE) - devc->sample_rate = analog_frame_size(sdi) / + if (devc->data_source == DATA_SOURCE_LIVE) { + devc->sample_rate = analog_frame_size(sdi) / (devc->timebase * devc->model->series->num_horizontal_divs); - else { + } else { float xinc; - if (devc->model->series->protocol >= PROTOCOL_V3 && - sr_scpi_get_float(sdi->conn, "WAV:XINC?", &xinc) != SR_OK) { - sr_err("Couldn't get sampling rate"); + if (devc->model->series->protocol < PROTOCOL_V3) { + sr_err("Cannot get samplerate (below V3)."); + return SR_ERR; + } + ret = sr_scpi_get_float(sdi->conn, "WAV:XINC?", &xinc); + if (ret != SR_OK) { + sr_err("Cannot get samplerate (WAV:XINC? failed)."); + return SR_ERR; + } + if (!xinc) { + sr_err("Cannot get samplerate (zero XINC value)."); return SR_ERR; } devc->sample_rate = 1. / xinc; } - if (rigol_ds_capture_start(sdi) != SR_OK) return SR_ERR;