]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/norma-dmm/protocol.c
usb: Skip add/remove of FD on destroyed source
[libsigrok.git] / src / hardware / norma-dmm / protocol.c
index 28f733c60ff5605570c213c22aaa64f51a7e82ad..35b1195723128a89994ea1aa1a1eb043983c9ccc 100644 (file)
  *  @internal
  */
 
+#include <config.h>
 #include "protocol.h"
 
+#define LINE_LENGTH 20
+
 SR_PRIV const struct nmadmm_req nmadmm_requests[] = {
        { NMADMM_REQ_IDN, "IDN?" },
        { NMADMM_REQ_IDN, "STATUS?" },
@@ -48,7 +51,8 @@ static int nma_send_req(const struct sr_dev_inst *sdi, int req, char *params)
        devc->last_req = req;
        devc->last_req_pending = TRUE;
 
-       if (serial_write_blocking(serial, buf, len, 0) < 0) {
+       if (serial_write_blocking(serial, buf, len,
+                       serial_timeout(serial, len)) < 0) {
                sr_err("Unable to send request.");
                devc->last_req_pending = FALSE;
                return SR_ERR;
@@ -92,19 +96,19 @@ static void nma_process_line(const struct sr_dev_inst *sdi)
 
        devc = sdi->priv;
 
-       devc->buf[20] = '\0';
+       devc->buf[LINE_LENGTH] = '\0';
 
        sr_spew("Received line '%s'.", devc->buf);
 
        /* Check line. */
-       if (strlen((const char *)devc->buf) != 20) {
+       if (strlen((const char *)devc->buf) != LINE_LENGTH) {
                sr_err("line: Invalid status '%s', must be 20 hex digits.",
                       devc->buf);
                devc->buflen = 0;
                return;
        }
 
-       for (pos = 0; pos < 20; pos++) {
+       for (pos = 0; pos < LINE_LENGTH; pos++) {
                if (!isxdigit(devc->buf[pos])) {
                        sr_err("line: Expected hex digit in '%s' at pos %d!",
                                devc->buf, pos);