2 * This file is part of the libsigrok project.
4 * Copyright (C) 2018 mhooijboer <marchelh@gmail.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #include <libsigrok/libsigrok.h>
29 #include "libsigrok-internal.h"
33 static const uint32_t scanopts[] = {
38 static const uint32_t drvopts[] = {
40 SR_CONF_LOGIC_ANALYZER,
43 static const uint32_t devopts[] = {
44 SR_CONF_TIMEBASE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
45 SR_CONF_TRIGGER_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
46 SR_CONF_TRIGGER_SLOPE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
47 SR_CONF_TRIGGER_LEVEL | SR_CONF_GET | SR_CONF_SET,
48 SR_CONF_HORIZ_TRIGGERPOS | SR_CONF_GET | SR_CONF_SET,
49 SR_CONF_NUM_HDIV | SR_CONF_GET | SR_CONF_LIST,
50 SR_CONF_SAMPLERATE | SR_CONF_GET,
51 SR_CONF_LIMIT_FRAMES | SR_CONF_GET | SR_CONF_SET,
52 SR_CONF_DATA_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
53 SR_CONF_AVERAGING | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
54 SR_CONF_AVG_SAMPLES | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
57 static const uint32_t devopts_cg_analog[] = {
58 SR_CONF_NUM_VDIV | SR_CONF_GET,
59 SR_CONF_VDIV | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
60 SR_CONF_TIMEBASE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
61 SR_CONF_COUPLING | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
62 SR_CONF_PROBE_FACTOR | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
63 SR_CONF_DATA_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
66 static const uint64_t timebases[][2] = {
107 static const uint64_t vdivs[][2] = {
130 static const char *trigger_sources[] = {
131 "CH1", "CH2", "Ext", "Ext /5", "AC Line",
132 "D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
133 "D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
136 static const char *trigger_slopes[] = {
140 static const char *coupling[] = {
148 static const uint64_t probe_factor[] = {
149 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000,
152 /* Do not change the order of entries. */
153 static const char *data_sources[] = {
172 /* short name, full name */
173 static const struct siglent_sds_vendor supported_vendors[] = {
174 [SIGLENT] = {"Siglent", "Siglent Technologies"},
177 #define VENDOR(x) &supported_vendors[x]
178 /* vendor, series, protocol, max timebase, min vdiv, number of horizontal divs,
179 * number of vertical divs, live waveform samples, memory buffer samples */
180 static const struct siglent_sds_series supported_series[] = {
181 [SDS1000CML] = {VENDOR(SIGLENT), "SDS1000CML", NON_SPO_MODEL,
182 { 50, 1 }, { 2, 1000 }, 18, 8, 1400363},
183 [SDS1000CNL] = {VENDOR(SIGLENT), "SDS1000CNL", NON_SPO_MODEL,
184 { 50, 1 }, { 2, 1000 }, 18, 8, 1400363},
185 [SDS1000DL] = {VENDOR(SIGLENT), "SDS1000DL", NON_SPO_MODEL,
186 { 50, 1 }, { 2, 1000 }, 18, 8, 1400363},
187 [SDS1000X] = {VENDOR(SIGLENT), "SDS1000X", SPO_MODEL,
188 { 50, 1 }, { 500, 100000 }, 14, 8, 14000363},
189 [SDS1000XP] = {VENDOR(SIGLENT), "SDS1000X+", SPO_MODEL,
190 { 50, 1 }, { 500, 100000 }, 14, 8, 14000363},
191 [SDS1000XE] = {VENDOR(SIGLENT), "SDS1000XE", SPO_MODEL,
192 { 50, 1 }, { 500, 100000 }, 14, 8, 14000363},
193 [SDS2000X] = {VENDOR(SIGLENT), "SDS2000X", SPO_MODEL,
194 { 50, 1 }, { 500, 100000 }, 14, 8, 14000363},
197 #define SERIES(x) &supported_series[x]
198 /* series, model, min timebase, analog channels, digital */
199 static const struct siglent_sds_model supported_models[] = {
200 { SERIES(SDS1000CML), "SDS1152CML", { 20, 1000000000 }, 2, false, 0 },
201 { SERIES(SDS1000CML), "SDS1102CML", { 10, 1000000000 }, 2, false, 0 },
202 { SERIES(SDS1000CML), "SDS1072CML", { 5, 1000000000 }, 2, false, 0 },
203 { SERIES(SDS1000CNL), "SDS1202CNL", { 20, 1000000000 }, 2, false, 0 },
204 { SERIES(SDS1000CNL), "SDS1102CNL", { 10, 1000000000 }, 2, false, 0 },
205 { SERIES(SDS1000CNL), "SDS1072CNL", { 5, 1000000000 }, 2, false, 0 },
206 { SERIES(SDS1000DL), "SDS1202DL", { 20, 1000000000 }, 2, false, 0 },
207 { SERIES(SDS1000DL), "SDS1102DL", { 10, 1000000000 }, 2, false, 0 },
208 { SERIES(SDS1000DL), "SDS1022DL", { 5, 1000000000 }, 2, false, 0 },
209 { SERIES(SDS1000DL), "SDS1052DL", { 5, 1000000000 }, 2, false, 0 },
210 { SERIES(SDS1000DL), "SDS1052DL+", { 5, 1000000000 }, 2, false, 0 },
211 { SERIES(SDS1000X), "SDS1102X", { 2, 1000000000 }, 2, false, 0 },
212 { SERIES(SDS1000XP), "SDS1102X+", { 2, 1000000000 }, 2, false, 0 },
213 { SERIES(SDS1000X), "SDS1202X", { 2, 1000000000 }, 2, false, 0 },
214 { SERIES(SDS1000XP), "SDS1202X+", { 2, 1000000000 }, 2, false, 0 },
215 { SERIES(SDS1000XE), "SDS1202X-E", { 1, 1000000000 }, 2, false, 0 },
216 { SERIES(SDS1000XE), "SDS1104X-E", { 1, 1000000000 }, 4, true, 16 },
217 { SERIES(SDS1000XE), "SDS1204X-E", { 1, 1000000000 }, 4, true, 16 },
218 { SERIES(SDS2000X), "SDS2072X", { 2, 1000000000 }, 2, false, 0 },
219 { SERIES(SDS2000X), "SDS2074X", { 2, 1000000000 }, 4, false, 0 },
220 { SERIES(SDS2000X), "SDS2102X", { 2, 1000000000 }, 2, false, 0 },
221 { SERIES(SDS2000X), "SDS2104X", { 2, 1000000000 }, 4, false, 0 },
222 { SERIES(SDS2000X), "SDS2202X", { 2, 1000000000 }, 2, false, 0 },
223 { SERIES(SDS2000X), "SDS2204X", { 2, 1000000000 }, 4, false, 0 },
224 { SERIES(SDS2000X), "SDS2302X", { 2, 1000000000 }, 2, false, 0 },
225 { SERIES(SDS2000X), "SDS2304X", { 2, 1000000000 }, 4, false, 0 },
228 SR_PRIV struct sr_dev_driver siglent_sds_driver_info;
230 static void clear_helper(void *priv)
232 struct dev_context *devc;
237 g_free(devc->analog_groups);
238 g_free(devc->enabled_channels);
241 static int dev_clear(const struct sr_dev_driver *di)
243 return std_dev_clear_with_callback(di, clear_helper);
246 static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
248 struct dev_context *devc;
249 struct sr_dev_inst *sdi;
250 struct sr_scpi_hw_info *hw_info;
251 struct sr_channel *ch;
253 const struct siglent_sds_model *model;
256 sr_dbg("Setting Communication Headers to off.");
257 if (sr_scpi_send(scpi, "CHDR OFF") != SR_OK)
260 if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) {
261 sr_info("Couldn't get IDN response, retrying.");
264 if (sr_scpi_get_hw_id(scpi, &hw_info) != SR_OK) {
265 sr_info("Couldn't get IDN response.");
271 for (i = 0; i < ARRAY_SIZE(supported_models); i++) {
272 if (!strcmp(hw_info->model, supported_models[i].name)) {
273 model = &supported_models[i];
279 sr_scpi_hw_info_free(hw_info);
283 sdi = g_malloc0(sizeof(struct sr_dev_inst));
284 sdi->vendor = g_strdup(model->series->vendor->name);
285 sdi->model = g_strdup(model->name);
286 sdi->version = g_strdup(hw_info->firmware_version);
288 sdi->driver = &siglent_sds_driver_info;
289 sdi->inst_type = SR_INST_SCPI;
290 sdi->serial_num = g_strdup(hw_info->serial_number);
291 devc = g_malloc0(sizeof(struct dev_context));
292 devc->limit_frames = 1;
295 sr_scpi_hw_info_free(hw_info);
297 devc->analog_groups = g_malloc0(sizeof(struct sr_channel_group *) *
298 model->analog_channels);
300 for (i = 0; i < model->analog_channels; i++) {
301 channel_name = g_strdup_printf("CH%d", i + 1);
302 ch = sr_channel_new(sdi, i, SR_CHANNEL_ANALOG, TRUE, channel_name);
304 devc->analog_groups[i] = g_malloc0(sizeof(struct sr_channel_group));
306 devc->analog_groups[i]->name = channel_name;
307 devc->analog_groups[i]->channels = g_slist_append(NULL, ch);
308 sdi->channel_groups = g_slist_append(sdi->channel_groups,
309 devc->analog_groups[i]);
312 if (devc->model->has_digital) {
313 devc->digital_group = g_malloc0(sizeof(struct sr_channel_group));
315 for (i = 0; i < ARRAY_SIZE(devc->digital_channels); i++) {
316 channel_name = g_strdup_printf("D%d", i);
317 ch = sr_channel_new(sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_name);
318 g_free(channel_name);
319 devc->digital_group->channels = g_slist_append(
320 devc->digital_group->channels, ch);
322 devc->digital_group->name = g_strdup("LA");
323 sdi->channel_groups = g_slist_append(sdi->channel_groups,
324 devc->digital_group);
327 for (i = 0; i < ARRAY_SIZE(timebases); i++) {
328 if (!memcmp(&devc->model->min_timebase, &timebases[i], sizeof(uint64_t[2])))
329 devc->timebases = &timebases[i];
331 if (!memcmp(&devc->model->series->max_timebase, &timebases[i], sizeof(uint64_t[2])))
332 devc->num_timebases = &timebases[i] - devc->timebases + 1;
335 for (i = 0; i < ARRAY_SIZE(vdivs); i++) {
336 devc->vdivs = &vdivs[i];
337 if (!memcmp(&devc->model->series->min_vdiv,
338 &vdivs[i], sizeof(uint64_t[2]))) {
339 devc->vdivs = &vdivs[i];
340 devc->num_vdivs = ARRAY_SIZE(vdivs) - i;
345 devc->buffer = g_malloc(devc->model->series->buffer_samples);
346 sr_dbg("Setting device context buffer size: %i.", devc->model->series->buffer_samples);
347 devc->data = g_malloc(devc->model->series->buffer_samples * sizeof(float));
349 devc->data_source = DATA_SOURCE_SCREEN;
356 static GSList *scan(struct sr_dev_driver *di, GSList *options)
358 /* TODO: Implement RPC call for LXI device discovery. */
359 return sr_scpi_scan(di->context, options, probe_device);
362 static int dev_open(struct sr_dev_inst *sdi)
365 struct sr_scpi_dev_inst *scpi = sdi->conn;
367 if ((ret = sr_scpi_open(scpi)) < 0) {
368 sr_err("Failed to open SCPI device: %s.", sr_strerror(ret));
372 if ((ret = siglent_sds_get_dev_cfg(sdi)) < 0) {
373 sr_err("Failed to get device config: %s.", sr_strerror(ret));
380 static int dev_close(struct sr_dev_inst *sdi)
382 return sr_scpi_close(sdi->conn);
385 static int config_get(uint32_t key, GVariant **data,
386 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
388 struct dev_context *devc;
389 struct sr_channel *ch;
391 int analog_channel = -1;
392 float smallest_diff = INFINITY;
401 /* If a channel group is specified, it must be a valid one. */
402 if (cg && !g_slist_find(sdi->channel_groups, cg)) {
403 sr_err("Invalid channel group specified.");
408 ch = g_slist_nth_data(cg->channels, 0);
411 if (ch->type == SR_CHANNEL_ANALOG) {
412 if (ch->name[2] < '1' || ch->name[2] > '4')
414 analog_channel = ch->name[2] - '1';
419 case SR_CONF_NUM_HDIV:
420 *data = g_variant_new_int32(devc->model->series->num_horizontal_divs);
422 case SR_CONF_NUM_VDIV:
423 *data = g_variant_new_int32(devc->num_vdivs);
425 case SR_CONF_LIMIT_FRAMES:
426 *data = g_variant_new_uint64(devc->limit_frames);
428 case SR_CONF_DATA_SOURCE:
429 if (devc->data_source == DATA_SOURCE_SCREEN)
430 *data = g_variant_new_string("Screen");
431 else if (devc->data_source == DATA_SOURCE_HISTORY)
432 *data = g_variant_new_string("History");
434 case SR_CONF_SAMPLERATE:
435 siglent_sds_get_dev_cfg_horizontal(sdi);
436 *data = g_variant_new_uint64(devc->samplerate);
438 case SR_CONF_TRIGGER_SOURCE:
439 if (!strcmp(devc->trigger_source, "ACL"))
441 else if (!strcmp(devc->trigger_source, "CHAN1"))
443 else if (!strcmp(devc->trigger_source, "CHAN2"))
446 tmp_str = devc->trigger_source;
447 *data = g_variant_new_string(tmp_str);
449 case SR_CONF_TRIGGER_SLOPE:
450 if (!strncmp(devc->trigger_slope, "POS", 3)) {
452 } else if (!strncmp(devc->trigger_slope, "NEG", 3)) {
455 sr_dbg("Unknown trigger slope: '%s'.", devc->trigger_slope);
458 *data = g_variant_new_string(tmp_str);
460 case SR_CONF_TRIGGER_LEVEL:
461 *data = g_variant_new_double(devc->trigger_level);
463 case SR_CONF_HORIZ_TRIGGERPOS:
464 *data = g_variant_new_double(devc->horiz_triggerpos);
466 case SR_CONF_TIMEBASE:
467 for (i = 0; i < devc->num_timebases; i++) {
470 tb = (float)devc->timebases[i][0] / devc->timebases[i][1];
471 diff = fabs(devc->timebase - tb);
472 if (diff < smallest_diff) {
473 smallest_diff = diff;
478 sr_dbg("Negative timebase index: %d.", idx);
481 *data = g_variant_new("(tt)", devc->timebases[idx][0],
482 devc->timebases[idx][1]);
485 if (analog_channel < 0) {
486 sr_dbg("Negative analog channel: %d.", analog_channel);
489 for (i = 0; i < ARRAY_SIZE(vdivs); i++) {
490 float vdiv = (float)vdivs[i][0] / vdivs[i][1];
491 float diff = fabsf(devc->vdiv[analog_channel] - vdiv);
492 if (diff < smallest_diff) {
493 smallest_diff = diff;
498 sr_dbg("Negative vdiv index: %d.", idx);
501 *data = g_variant_new("(tt)", vdivs[idx][0], vdivs[idx][1]);
503 case SR_CONF_COUPLING:
504 if (analog_channel < 0) {
505 sr_dbg("Negative analog channel: %d.", analog_channel);
508 *data = g_variant_new_string(devc->coupling[analog_channel]);
510 case SR_CONF_PROBE_FACTOR:
511 if (analog_channel < 0) {
512 sr_dbg("Negative analog channel: %d.", analog_channel);
515 *data = g_variant_new_uint64(devc->attenuation[analog_channel]);
524 static int config_set(uint32_t key, GVariant *data,
525 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
527 struct dev_context *devc;
539 /* If a channel group is specified, it must be a valid one. */
540 if (cg && !g_slist_find(sdi->channel_groups, cg)) {
541 sr_err("Invalid channel group specified.");
547 case SR_CONF_LIMIT_FRAMES:
548 devc->limit_frames = g_variant_get_uint64(data);
550 case SR_CONF_TRIGGER_SLOPE:
551 if ((idx = std_str_idx(data, ARRAY_AND_SIZE(trigger_slopes))) < 0)
553 g_free(devc->trigger_slope);
554 devc->trigger_slope = g_strdup((trigger_slopes[idx][0] == 'r') ? "POS" : "NEG");
555 return siglent_sds_config_set(sdi, "%s:TRSL %s",
556 devc->trigger_source, devc->trigger_slope);
557 case SR_CONF_HORIZ_TRIGGERPOS:
558 t_dbl = g_variant_get_double(data);
559 if (t_dbl < 0.0 || t_dbl > 1.0) {
560 sr_err("Invalid horiz. trigger position: %g.", t_dbl);
563 devc->horiz_triggerpos = t_dbl;
564 /* We have the trigger offset as a percentage of the frame, but
565 * need to express this in seconds. */
566 t_dbl = -(devc->horiz_triggerpos - 0.5) * devc->timebase * devc->num_timebases;
567 g_ascii_formatd(buffer, sizeof(buffer), "%.6f", t_dbl);
568 return siglent_sds_config_set(sdi, ":TIM:OFFS %s", buffer);
569 case SR_CONF_TRIGGER_LEVEL:
570 t_dbl = g_variant_get_double(data);
571 g_ascii_formatd(buffer, sizeof(buffer), "%.3f", t_dbl);
572 ret = siglent_sds_config_set(sdi, ":TRIG:EDGE:LEV %s", buffer);
574 devc->trigger_level = t_dbl;
576 case SR_CONF_TIMEBASE:
577 if ((idx = std_u64_tuple_idx(data, devc->timebases, devc->num_timebases)) < 0)
579 devc->timebase = (float)devc->timebases[idx][0] / devc->timebases[idx][1];
580 p = devc->timebases[idx][0];
581 switch (devc->timebases[idx][1]) {
583 cmd = g_strdup_printf("%" PRIu64 "S", p);
586 cmd = g_strdup_printf("%" PRIu64 "MS", p);
589 cmd = g_strdup_printf("%" PRIu64 "US", p);
592 cmd = g_strdup_printf("%" PRIu64 "NS", p);
595 ret = siglent_sds_config_set(sdi, "TDIV %s", cmd);
598 case SR_CONF_TRIGGER_SOURCE:
599 if ((idx = std_str_idx(data, ARRAY_AND_SIZE(trigger_sources))) < 0)
601 g_free(devc->trigger_source);
602 devc->trigger_source = g_strdup(trigger_sources[idx]);
603 if (!strcmp(devc->trigger_source, "AC Line"))
605 else if (!strcmp(devc->trigger_source, "CH1"))
607 else if (!strcmp(devc->trigger_source, "CH2"))
609 else if (!strcmp(devc->trigger_source, "CH3"))
611 else if (!strcmp(devc->trigger_source, "CH4"))
613 else if (!strcmp(devc->trigger_source, "Ext"))
615 else if (!strcmp(devc->trigger_source, "Ext /5"))
618 tmp_str = (char *)devc->trigger_source;
619 return siglent_sds_config_set(sdi, "TRSE EDGE,SR,%s,OFF", tmp_str);
622 return SR_ERR_CHANNEL_GROUP;
623 if ((i = std_cg_idx(cg, devc->analog_groups, devc->model->analog_channels)) < 0)
625 if ((idx = std_u64_tuple_idx(data, ARRAY_AND_SIZE(vdivs))) < 0)
627 devc->vdiv[i] = (float)vdivs[idx][0] / vdivs[idx][1];
629 switch (vdivs[idx][1]) {
631 cmd = g_strdup_printf("%" PRIu64 "V", p);
634 cmd = g_strdup_printf("%" PRIu64 "MV", p);
637 cmd = g_strdup_printf("%" PRIu64 "UV", p);
640 ret = siglent_sds_config_set(sdi, "C%d:VDIV %s", i + 1, cmd);
643 case SR_CONF_COUPLING:
645 return SR_ERR_CHANNEL_GROUP;
646 if ((i = std_cg_idx(cg, devc->analog_groups, devc->model->analog_channels)) < 0)
648 if ((idx = std_str_idx(data, ARRAY_AND_SIZE(coupling))) < 0)
650 g_free(devc->coupling[i]);
651 devc->coupling[i] = g_strdup(coupling[idx]);
652 strncpy(cmd4, devc->coupling[i], 3);
654 return siglent_sds_config_set(sdi, "C%d:CPL %s", i + 1, cmd4);
655 case SR_CONF_PROBE_FACTOR:
657 return SR_ERR_CHANNEL_GROUP;
658 if ((i = std_cg_idx(cg, devc->analog_groups, devc->model->analog_channels)) < 0)
660 if ((idx = std_u64_idx(data, ARRAY_AND_SIZE(probe_factor))) < 0)
662 p = g_variant_get_uint64(data);
663 devc->attenuation[i] = probe_factor[idx];
664 ret = siglent_sds_config_set(sdi, "C%d:ATTN %" PRIu64, i + 1, p);
666 siglent_sds_get_dev_cfg_vertical(sdi);
668 case SR_CONF_DATA_SOURCE:
669 tmp_str = g_variant_get_string(data, NULL);
670 if (!strcmp(tmp_str, "Display"))
671 devc->data_source = DATA_SOURCE_SCREEN;
672 else if (devc->model->series->protocol >= SPO_MODEL
673 && !strcmp(tmp_str, "History"))
674 devc->data_source = DATA_SOURCE_HISTORY;
676 sr_err("Unknown data source: '%s'.", tmp_str);
680 case SR_CONF_SAMPLERATE:
681 siglent_sds_get_dev_cfg_horizontal(sdi);
682 data = g_variant_new_uint64(devc->samplerate);
684 case SR_CONF_AVERAGING:
685 devc->average_enabled = g_variant_get_boolean(data);
686 sr_dbg("%s averaging", devc->average_enabled ? "Enabling" : "Disabling");
688 case SR_CONF_AVG_SAMPLES:
689 devc->average_samples = g_variant_get_uint64(data);
690 sr_dbg("Setting averaging rate to %" PRIu64, devc->average_samples);
699 static int config_list(uint32_t key, GVariant **data,
700 const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
702 struct dev_context *devc;
704 devc = (sdi) ? sdi->priv : NULL;
707 case SR_CONF_SCAN_OPTIONS:
708 case SR_CONF_DEVICE_OPTIONS:
710 return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts);
713 if (cg == devc->digital_group) {
714 *data = std_gvar_array_u32(NULL, 0);
717 if (std_cg_idx(cg, devc->analog_groups, devc->model->analog_channels) < 0)
719 *data = std_gvar_array_u32(ARRAY_AND_SIZE(devopts_cg_analog));
723 case SR_CONF_COUPLING:
725 return SR_ERR_CHANNEL_GROUP;
726 *data = g_variant_new_strv(ARRAY_AND_SIZE(coupling));
728 case SR_CONF_PROBE_FACTOR:
730 return SR_ERR_CHANNEL_GROUP;
731 *data = std_gvar_array_u64(ARRAY_AND_SIZE(probe_factor));
735 /* Can't know this until we have the exact model. */
738 return SR_ERR_CHANNEL_GROUP;
739 *data = std_gvar_tuple_array(devc->vdivs, devc->num_vdivs);
741 case SR_CONF_TIMEBASE:
743 /* Can't know this until we have the exact model. */
745 if (devc->num_timebases <= 0)
747 *data = std_gvar_tuple_array(devc->timebases, devc->num_timebases);
749 case SR_CONF_TRIGGER_SOURCE:
751 /* Can't know this until we have the exact model. */
753 *data = g_variant_new_strv(trigger_sources,
754 devc->model->has_digital ? ARRAY_SIZE(trigger_sources) : 5);
756 case SR_CONF_TRIGGER_SLOPE:
757 *data = g_variant_new_strv(ARRAY_AND_SIZE(trigger_slopes));
759 case SR_CONF_DATA_SOURCE:
761 /* Can't know this until we have the exact model. */
763 switch (devc->model->series->protocol) {
764 /* TODO: Check what must be done here for the data source buffer sizes. */
766 *data = g_variant_new_strv(data_sources, ARRAY_SIZE(data_sources) - 1);
769 *data = g_variant_new_strv(ARRAY_AND_SIZE(data_sources));
773 case SR_CONF_NUM_HDIV:
774 *data = g_variant_new_int32(devc->model->series->num_horizontal_divs);
776 case SR_CONF_AVERAGING:
777 *data = g_variant_new_boolean(devc->average_enabled);
786 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
788 struct sr_scpi_dev_inst *scpi;
789 struct dev_context *devc;
790 struct sr_channel *ch;
791 struct sr_datafeed_packet packet;
792 gboolean some_digital;
798 devc->num_frames = 0;
799 some_digital = FALSE;
802 * Check if there are any logic channels enabled, if so then enable
803 * the MSO, otherwise skip the digital channel setup. Enable and
804 * disable channels on the device is very slow and it is faster when
805 * checked in a small loop without the actual actions.
807 for (d = sdi->channels; d; d = d->next) {
809 if (ch->type == SR_CHANNEL_LOGIC && ch->enabled)
813 for (l = sdi->channels; l; l = l->next) {
815 if (ch->type == SR_CHANNEL_ANALOG) {
817 devc->enabled_channels = g_slist_append(
818 devc->enabled_channels, ch);
819 if (ch->enabled != devc->analog_channels[ch->index]) {
820 /* Enabled channel is currently disabled, or vice versa. */
821 if (siglent_sds_config_set(sdi, "C%d:TRA %s", ch->index + 1,
822 ch->enabled ? "ON" : "OFF") != SR_OK)
824 devc->analog_channels[ch->index] = ch->enabled;
826 } else if (ch->type == SR_CHANNEL_LOGIC && some_digital) {
828 /* Turn on LA module if currently off and digital channels are enabled. */
829 if (!devc->la_enabled) {
830 if (siglent_sds_config_set(sdi, "DGST ON") != SR_OK)
833 devc->la_enabled = TRUE;
835 devc->enabled_channels = g_slist_append(
836 devc->enabled_channels, ch);
838 /* Enabled channel is currently disabled, or vice versa. */
839 if (siglent_sds_config_set(sdi, "D%d:DGCH %s", ch->index,
840 ch->enabled ? "ON" : "OFF") != SR_OK)
842 /* Slowing the command sequence down to let the device handle it. */
844 devc->digital_channels[ch->index] = ch->enabled;
847 if (!devc->enabled_channels)
849 /* Turn off LA module if on and no digital channels selected. */
850 if (devc->la_enabled && !some_digital)
851 if (siglent_sds_config_set(sdi, "DGST OFF") != SR_OK) {
852 devc->la_enabled = FALSE;
857 // devc->analog_frame_size = devc->model->series->buffer_samples;
858 // devc->digital_frame_size = devc->model->series->buffer_samples;
860 siglent_sds_get_dev_cfg_horizontal(sdi);
861 switch (devc->model->series->protocol) {
863 if (siglent_sds_config_set(sdi, "WFSU SP,0,TYPE,1") != SR_OK)
865 if (devc->average_enabled) {
866 if (siglent_sds_config_set(sdi, "ACQW AVERAGE,%i", devc->average_samples) != SR_OK)
869 if (siglent_sds_config_set(sdi, "ACQW SAMPLING") != SR_OK)
874 /* TODO: Implement CML/CNL/DL models. */
875 if (siglent_sds_config_set(sdi, "WFSU SP,0,TYPE,1") != SR_OK)
877 if (siglent_sds_config_set(sdi, "ACQW SAMPLING") != SR_OK)
884 sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 50,
885 siglent_sds_receive, (void *) sdi);
887 std_session_send_df_header(sdi);
889 devc->channel_entry = devc->enabled_channels;
891 if (siglent_sds_capture_start(sdi) != SR_OK)
894 /* Start of first frame. */
895 packet.type = SR_DF_FRAME_BEGIN;
896 sr_session_send(sdi, &packet);
901 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
903 struct dev_context *devc;
904 struct sr_scpi_dev_inst *scpi;
908 std_session_send_df_end(sdi);
910 g_slist_free(devc->enabled_channels);
911 devc->enabled_channels = NULL;
913 sr_scpi_source_remove(sdi->session, scpi);
918 SR_PRIV struct sr_dev_driver siglent_sds_driver_info = {
919 .name = "siglent-sds",
920 .longname = "Siglent SDS1000/SDS2000",
923 .cleanup = std_cleanup,
925 .dev_list = std_dev_list,
926 .dev_clear = dev_clear,
927 .config_get = config_get,
928 .config_set = config_set,
929 .config_list = config_list,
930 .dev_open = dev_open,
931 .dev_close = dev_close,
932 .dev_acquisition_start = dev_acquisition_start,
933 .dev_acquisition_stop = dev_acquisition_stop,
937 SR_REGISTER_DEV_DRIVER(siglent_sds_driver_info);