X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fscpi%2Fscpi.c;h=f72164a63f177dce0b71dd5d07fbc312566dadd8;hb=d2cc60bd4511c1154eef67e4c7abccb3fd34faab;hp=2477cf2323971c314880c3bc235732fd076c0af3;hpb=bb0665868eee7ebd569a6563d30c4099cf0c37bb;p=libsigrok.git diff --git a/src/scpi/scpi.c b/src/scpi/scpi.c index 2477cf23..f72164a6 100644 --- a/src/scpi/scpi.c +++ b/src/scpi/scpi.c @@ -1114,15 +1114,24 @@ 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. + * + * 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); - if (num_tokens < 4) { - sr_dbg("IDN response not according to spec: %80.s.", response); + if (num_tokens < 3) { + sr_dbg("IDN response not according to spec: '%s'", response); g_strfreev(tokens); 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)); @@ -1134,8 +1143,13 @@ SR_PRIV int sr_scpi_get_hw_id(struct sr_scpi_dev_inst *scpi, hw_info->manufacturer = g_strstrip(g_strdup(idn_substr + 4)); hw_info->model = g_strstrip(g_strdup(tokens[1])); - hw_info->serial_number = g_strstrip(g_strdup(tokens[2])); - hw_info->firmware_version = g_strstrip(g_strdup(tokens[3])); + if (num_tokens < 4) { + hw_info->serial_number = g_strdup("Unknown"); + hw_info->firmware_version = g_strstrip(g_strdup(tokens[2])); + } else { + hw_info->serial_number = g_strstrip(g_strdup(tokens[2])); + hw_info->firmware_version = g_strstrip(g_strdup(tokens[3])); + } g_strfreev(tokens);