]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/zketech-ebd-usb/protocol.c
kingst-la2016: fix segfault that often occurs when a capture is aborted
[libsigrok.git] / src / hardware / zketech-ebd-usb / protocol.c
index be4aa285e2bad66ff0fff9e6c5e2515a46b2024b..4c586f6fd71989deec056a650a2abf96fb4e29a2 100644 (file)
@@ -30,7 +30,7 @@ static void log_buf(const char *message, uint8_t buf[], size_t count)
 
        buffer[count * 2] = 0;
 
-       sr_dbg("%s: %s [%lu bytes]", message, buffer, count);
+       sr_dbg("%s: %s [%zu bytes]", message, buffer, count);
 }
 
 /* Send a command to the device. */
@@ -44,7 +44,6 @@ static int send_cmd(struct sr_serial_dev_inst *serial, uint8_t buf[], size_t cou
                sr_err("Error sending command: %d.", ret);
                return ret;
        }
-       sr_dbg("Sent %d bytes.", ret);
 
        return (ret == (int)count) ? SR_OK : SR_ERR;
 }
@@ -100,6 +99,9 @@ SR_PRIV int ebd_loadstart(struct sr_serial_dev_inst *serial, struct dev_context
        int ret;
 
        ret = send_cmd(serial, start, 10);
+       if (ret)
+               return ret;
+
        sr_dbg("Current limit: %f.", devc->current_limit);
        if (ebd_current_is0(devc))
                return SR_OK;
@@ -225,9 +227,7 @@ SR_PRIV int ebd_receive_data(int fd, int revents, void *cb_data)
        sr_dbg("Current limit %f", current_limit);
 
        /* Begin frame. */
-       packet.type = SR_DF_FRAME_BEGIN;
-       packet.payload = NULL;
-       sr_session_send(sdi, &packet);
+       std_session_send_df_frame_begin(sdi);
 
        sr_analog_init(&analog, &encoding, &meaning, &spec, 4);
 
@@ -258,9 +258,7 @@ SR_PRIV int ebd_receive_data(int fd, int revents, void *cb_data)
        g_slist_free(l);
 
        /* End frame. */
-       packet.type = SR_DF_FRAME_END;
-       packet.payload = NULL;
-       sr_session_send(sdi, &packet);
+       std_session_send_df_frame_end(sdi);
 
        sr_sw_limits_update_samples_read(&devc->limits, 1);
        if (sr_sw_limits_check(&devc->limits))