]> sigrok.org Git - libsigrok.git/commitdiff
scpi: Raise severity when IDN response lacks the serial number field.
authorGerhard Sittig <redacted>
Mon, 17 Aug 2020 17:07:37 +0000 (19:07 +0200)
committerGerhard Sittig <redacted>
Mon, 17 Aug 2020 17:07:37 +0000 (19:07 +0200)
Raise the diagnostics message's severity from debug to warn when the
'*IDN?' response lacks the serial number field. Although it has only
been seen for some GWInstek DMMs, it violates the SCPI spec, and more
or other activity is required in a future implementation. This change
amends commit 47e7a6395e21.

src/scpi/scpi.c

index cc213ff87e013788bc35676ba217658ca596fb4e..f72164a63f177dce0b71dd5d07fbc312566dadd8 100644 (file)
@@ -1114,6 +1114,12 @@ SR_PRIV int sr_scpi_get_hw_id(struct sr_scpi_dev_inst *scpi,
         * The response to a '*IDN?' is specified by the SCPI spec. It contains
         * a comma-separated list containing the manufacturer name, instrument
         * model, serial number of the instrument and the firmware version.
         * The response to a '*IDN?' is specified by the SCPI spec. It contains
         * a comma-separated list containing the manufacturer name, instrument
         * model, serial number of the instrument and the firmware version.
+        *
+        * BEWARE! Although strictly speaking a smaller field count is invalid,
+        * this implementation also accepts IDN responses with one field less,
+        * and assumes that the serial number is missing. Some GWInstek DMMs
+        * were found to do this. Keep warning about this condition, which may
+        * need more consideration later.
         */
        tokens = g_strsplit(response, ",", 0);
        num_tokens = g_strv_length(tokens);
         */
        tokens = g_strsplit(response, ",", 0);
        num_tokens = g_strv_length(tokens);
@@ -1123,6 +1129,9 @@ SR_PRIV int sr_scpi_get_hw_id(struct sr_scpi_dev_inst *scpi,
                g_free(response);
                return SR_ERR_DATA;
        }
                g_free(response);
                return SR_ERR_DATA;
        }
+       if (num_tokens < 4) {
+               sr_warn("Short IDN response, assume missing serial number.");
+       }
        g_free(response);
 
        hw_info = g_malloc0(sizeof(struct sr_scpi_hw_info));
        g_free(response);
 
        hw_info = g_malloc0(sizeof(struct sr_scpi_hw_info));