X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fscpi%2Fscpi.c;h=9fa4ac03605392245ca0077f468cd006bb99f235;hb=c16effaedc3a3d8539065d1cf228e98f8cace5e0;hp=cc213ff87e013788bc35676ba217658ca596fb4e;hpb=47e7a6395e21c664ab54642b9f77a10af10efdd5;p=libsigrok.git diff --git a/src/scpi/scpi.c b/src/scpi/scpi.c index cc213ff8..9fa4ac03 100644 --- a/src/scpi/scpi.c +++ b/src/scpi/scpi.c @@ -724,6 +724,7 @@ SR_PRIV int sr_scpi_get_int(struct sr_scpi_dev_inst *scpi, const char *command, int *scpi_response) { int ret; + struct sr_rational ret_rational; char *response; response = NULL; @@ -732,10 +733,14 @@ SR_PRIV int sr_scpi_get_int(struct sr_scpi_dev_inst *scpi, if (ret != SR_OK && !response) return ret; - if (sr_atoi(response, scpi_response) == SR_OK) - ret = SR_OK; - else + ret = sr_parse_rational(response, &ret_rational); + if (ret == SR_OK && (ret_rational.p % ret_rational.q) == 0) { + *scpi_response = ret_rational.p / ret_rational.q; + } else { + sr_dbg("get_int: non-integer rational=%" PRId64 "/%" PRIu64, + ret_rational.p, ret_rational.q); ret = SR_ERR_DATA; + } g_free(response); @@ -1114,6 +1119,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. + * + * 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); @@ -1123,6 +1134,9 @@ SR_PRIV int sr_scpi_get_hw_id(struct sr_scpi_dev_inst *scpi, 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));