X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Frigol-ds%2Fapi.c;h=6b92fa8de091ec5a943402fc6a8bd25f0a754abe;hb=81a9ab725f9ce9125c9bc22bc5ebd2903c26bc35;hp=370d1f72369656e7fc6b75fa809642f674244d84;hpb=17b5b202640c1ea5de09b0685a5ed6635f2e06df;p=libsigrok.git diff --git a/hardware/rigol-ds/api.c b/hardware/rigol-ds/api.c index 370d1f72..6b92fa8d 100644 --- a/hardware/rigol-ds/api.c +++ b/hardware/rigol-ds/api.c @@ -30,6 +30,7 @@ static const int32_t hwopts[] = { SR_CONF_CONN, + SR_CONF_SERIALCOMM }; static const int32_t hwcaps[] = { @@ -163,6 +164,16 @@ static const struct rigol_ds_model supported_models[] = { {"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; @@ -192,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 (sr_scpi_send(sdi->conn, buf) != SR_OK) + + if (ret != SR_OK) return SR_ERR; /* When setting a bunch of parameters in a row, the DS1052E scrambles @@ -213,10 +225,13 @@ 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; + 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; @@ -225,8 +240,30 @@ static int probe_port(const char *port, GSList **devices) gchar *channel_name; *devices = NULL; - if (!(scpi = scpi_usbtmc_dev_inst_new(port))) - return SR_ERR_MALLOC; + + 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); + 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; + } if (sr_scpi_open(scpi) != SR_OK) { sr_scpi_free(scpi); @@ -242,6 +279,7 @@ static int probe_port(const char *port, GSList **devices) if (strcasecmp(hw_info->manufacturer, "Rigol Technologies")) { sr_scpi_hw_info_free(hw_info); + sr_scpi_close(scpi); sr_scpi_free(scpi); return SR_ERR_NA; } @@ -257,11 +295,13 @@ static int probe_port(const char *port, GSList **devices) hw_info->manufacturer, hw_info->model, hw_info->firmware_version))) { sr_scpi_hw_info_free(hw_info); + sr_scpi_close(scpi); sr_scpi_free(scpi); return SR_ERR_NA; } sr_scpi_hw_info_free(hw_info); + sr_scpi_close(scpi); sdi->conn = scpi; @@ -339,21 +379,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))) @@ -362,8 +411,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;