]> sigrok.org Git - libsigrok.git/commitdiff
rigol-ds: Support RS232 connection.
authorMartin Ling <redacted>
Wed, 4 Dec 2013 12:49:38 +0000 (12:49 +0000)
committerMartin Ling <redacted>
Wed, 4 Dec 2013 12:50:12 +0000 (12:50 +0000)
Probing tested OK over RS232 for DS1052E and DS1102D. Capture needs work.

hardware/rigol-ds/api.c

index e578d5b9faf20416ca48976e7994003e35f26e34..4c8509196afa22377be05b9bb9a966f6b827ddeb 100644 (file)
@@ -30,6 +30,7 @@
 
 static const int32_t hwopts[] = {
        SR_CONF_CONN,
+       SR_CONF_SERIALCOMM
 };
 
 static const int32_t hwcaps[] = {
@@ -214,10 +215,11 @@ 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 *port, const char *serialcomm, GSList **devices)
 {
        struct dev_context *devc;
        struct sr_dev_inst *sdi;
+       const char *usbtmc_prefix = "/dev/usbtmc";
        struct sr_scpi_dev_inst *scpi;
        struct sr_scpi_hw_info *hw_info;
        struct sr_probe *probe;
@@ -226,8 +228,15 @@ 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(port, usbtmc_prefix, strlen(usbtmc_prefix)) == 0) {
+               if (!(scpi = scpi_usbtmc_dev_inst_new(port)))
+                       return SR_ERR_MALLOC;
+       } else {
+               if (!(scpi = scpi_serial_dev_inst_new(port, serialcomm)))
+                       return SR_ERR_MALLOC;
+       }
 
        if (sr_scpi_open(scpi) != SR_OK) {
                sr_scpi_free(scpi);
@@ -340,21 +349,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)))
@@ -363,8 +381,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;