]> sigrok.org Git - libsigrok.git/blobdiff - hardware/uni-t-dmm/protocol.c
rigol-ds1xx2: Autoprobe for usbtmc devices on Linux.
[libsigrok.git] / hardware / uni-t-dmm / protocol.c
index 96d26a65085e302f2751ed30b874d5b4e71f47a5..929ba9ecf6a42a382a2c8bc33d96f81d11a7893a 100644 (file)
@@ -77,6 +77,7 @@ static void decode_packet(struct dev_context *devc, int dmm, const uint8_t *buf)
        memset(&analog, 0, sizeof(struct sr_datafeed_analog));
 
        /* Parse the protocol packet. */
+       ret = SR_ERR;
        if (dmm == UNI_T_UT61D)
                ret = sr_dmm_parse_fs9922(buf, &floatval, &analog);
        else if (dmm == VOLTCRAFT_VC820)
@@ -106,7 +107,8 @@ static int hid_chip_init(struct dev_context *devc, uint16_t baudrate)
        if (libusb_kernel_driver_active(devc->usb->devhdl, 0) == 1) {
                ret = libusb_detach_kernel_driver(devc->usb->devhdl, 0);
                if (ret < 0) {
-                       sr_err("Failed to detach kernel driver: %d.", ret);
+                       sr_err("Failed to detach kernel driver: %s.",
+                              libusb_error_name(ret));
                        return SR_ERR;
                }
                sr_dbg("Successfully detached kernel driver.");
@@ -116,7 +118,8 @@ static int hid_chip_init(struct dev_context *devc, uint16_t baudrate)
 
        /* Claim interface 0. */
        if ((ret = libusb_claim_interface(devc->usb->devhdl, 0)) < 0) {
-               sr_err("Failed to claim interface 0: %d.", ret);
+               sr_err("Failed to claim interface 0: %s.",
+                      libusb_error_name(ret));
                return SR_ERR;
        }
        sr_dbg("Successfully claimed interface 0.");
@@ -145,7 +148,7 @@ static int hid_chip_init(struct dev_context *devc, uint16_t baudrate)
                1000 /* timeout (ms) */);
 
        if (ret < 0) {
-               sr_err("HID feature report error: %d.", ret);
+               sr_err("HID feature report error: %s.", libusb_error_name(ret));
                return SR_ERR;
        }
 
@@ -216,7 +219,7 @@ static int uni_t_dmm_receive_data(int fd, int revents, int dmm, void *cb_data)
                1000 /* timeout (ms) */);
 
        if (ret < 0) {
-               sr_err("USB receive error: %d.", ret);
+               sr_err("USB receive error: %s.", libusb_error_name(ret));
                return FALSE;
        }
 
@@ -262,7 +265,7 @@ static int uni_t_dmm_receive_data(int fd, int revents, int dmm, void *cb_data)
        }
 
        /* Abort acquisition if we acquired enough samples. */
-       if (devc->num_samples >= devc->limit_samples && devc->limit_samples > 0) {
+       if (devc->limit_samples && devc->num_samples >= devc->limit_samples) {
                sr_info("Requested number of samples reached.");
                sdi->driver->dev_acquisition_stop(sdi, cb_data);
        }