]> sigrok.org Git - libsigrok.git/blobdiff - src/dmm/metex14.c
dmm/metex14: unbreak packet request helper return code
[libsigrok.git] / src / dmm / metex14.c
index 2f76672f761c1709965c89cec888f782a5e9a0c8..d93052a85b84bc7cbfbe50b5b3c266df50dbf665 100644 (file)
@@ -22,7 +22,6 @@
  *
  * Metex 14-bytes ASCII protocol parser.
  *
- * @internal
  * This should work for various multimeters which use this kind of protocol,
  * even though there is some variation in which modes each DMM supports.
  *
@@ -171,9 +170,12 @@ static void parse_flags(const char *buf, struct metex14_info *info)
        info->is_gain = !strncmp(buf, "DB", 2) && info->is_decibel;
        info->is_power = (!strncmp(buf, "dB", 2) && info->is_decibel_mw) ||
                ((!strncmp(buf, "WT", 2) && info->is_watt));
+       info->is_power_factor = !strncmp(buf, "CO", 2) && info->is_unitless;
        info->is_hfe = !strncmp(buf, "HF", 2) ||
-               (!strncmp(buf, "  ", 2) && !info->is_volt && !info->is_ohm &&
-                !info->is_logic && !info->is_farad && !info->is_hertz);
+               (!strncmp(buf, "  ", 2) && !info->is_ampere &&!info->is_volt &&
+               !info->is_resistance && !info->is_capacity && !info->is_frequency &&
+               !info->is_temperature && !info->is_power && !info->is_power_factor &&
+               !info->is_gain && !info->is_logic && !info->is_diode);
        info->is_min = !strncmp(buf, "MN", 2);
        info->is_max = !strncmp(buf, "MX", 2);
        info->is_avg = !strncmp(buf, "AG", 2);
@@ -254,6 +256,10 @@ static void handle_flags(struct sr_datafeed_analog *analog, float *floatval,
                else
                        analog->meaning->unit = SR_UNIT_UNITLESS;
        }
+       if (info->is_power_factor) {
+               analog->meaning->mq = SR_MQ_POWER_FACTOR;
+               analog->meaning->unit = SR_UNIT_UNITLESS;
+       }
        if (info->is_gain) {
                analog->meaning->mq = SR_MQ_GAIN;
                analog->meaning->unit = SR_UNIT_DECIBEL_VOLT;
@@ -322,14 +328,23 @@ static gboolean flags_valid(const struct metex14_info *info)
        return TRUE;
 }
 
-#ifdef HAVE_LIBSERIALPORT
+#ifdef HAVE_SERIAL_COMM
 SR_PRIV int sr_metex14_packet_request(struct sr_serial_dev_inst *serial)
 {
        const uint8_t wbuf = 'D';
+       size_t wrlen;
+       int ret;
 
        sr_spew("Requesting DMM packet.");
 
-       return serial_write_blocking(serial, &wbuf, 1, 0);
+       wrlen = sizeof(wbuf);
+       ret = serial_write_blocking(serial, &wbuf, wrlen, 0);
+       if (ret < 0)
+               return ret;
+       if ((size_t)ret != wrlen)
+               return SR_ERR_IO;
+
+       return SR_OK;
 }
 #endif
 
@@ -389,7 +404,7 @@ SR_PRIV int sr_metex14_parse(const uint8_t *buf, float *floatval,
        int ret, exponent = 0;
        struct metex14_info *info_local;
 
-       info_local = (struct metex14_info *)info;
+       info_local = info;
 
        /* Don't print byte 13. That one contains the carriage return. */
        sr_dbg("DMM packet: \"%.13s\"", buf);