]> sigrok.org Git - libsigrok.git/blobdiff - src/scpi/scpi_serial.c
hameg-hmo: Try to find a valid serialcomm if none is supplied.
[libsigrok.git] / src / scpi / scpi_serial.c
index c73d1b4841a70ae434f50a6222d3555d881828ee..8690d6f146485ab65b7cc2a737b17708e101f1b7 100644 (file)
@@ -74,11 +74,30 @@ static GSList *scpi_serial_scan(struct drv_context *drvc)
 static int scpi_serial_dev_inst_new(void *priv, struct drv_context *drvc,
                const char *resource, char **params, const char *serialcomm)
 {
+       GSList *l, *r;
+       unsigned i;
        struct scpi_serial *sscpi = priv;
 
        (void)drvc;
        (void)params;
 
+       /* If no serial port option is specified on the command-line using the
+        * "serialcomm" driver option, but the device is connected through USB
+        * and it requires a known default serial port option, then used it in
+        * order to avoid data corruption or even worse problems.
+        */
+       if (!serialcomm) {
+               for (i = 0; i < ARRAY_SIZE(scpi_serial_usb_ids); i++) {
+                       if (!(l = sr_serial_find_usb(scpi_serial_usb_ids[i].vendor_id,
+                                               scpi_serial_usb_ids[i].product_id)))
+                               continue;
+                       for (r = l; r; r = r->next)
+                               if (!strcmp(resource, r->data) && scpi_serial_usb_ids[i].serialcomm)
+                                       serialcomm = scpi_serial_usb_ids[i].serialcomm;
+                       g_slist_free_full(l, g_free);
+               }
+       }
+
        sscpi->serial = sr_serial_dev_inst_new(resource, serialcomm);
 
        return SR_OK;