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.

Note: the easiest way to reproduce data corruption on HMO3000 series
is to start an analog data acquisition (e.g. on channel CH1) after
switching from Ethernet mode to USB VCP mode.

Signed-off-by: Guido Trentalancia <gu...@trentalancia.com>
---
 src/scpi/scpi_serial.c |   19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff -pru libsigrok-git-20102018-orig/src/scpi/scpi_serial.c 
libsigrok-git-20102018-fix-hameg-hmo-default-usb-serial-port-options/src/scpi/scpi_serial.c
--- libsigrok-git-20102018-orig/src/scpi/scpi_serial.c  2018-10-20 
13:12:30.983966965 +0200
+++ 
libsigrok-git-20102018-fix-hameg-hmo-default-usb-serial-port-options/src/scpi/scpi_serial.c
 2018-10-30 21:21:24.312151481 +0100
@@ -72,11 +73,30 @@ static GSList *scpi_serial_scan(struct d
 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;


_______________________________________________
sigrok-devel mailing list
sigrok-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sigrok-devel

Reply via email to