]> sigrok.org Git - libsigrok.git/commitdiff
Use new libserialport blocking/nonblocking API calls.
authorMartin Ling <redacted>
Wed, 27 Nov 2013 01:43:49 +0000 (01:43 +0000)
committerUwe Hermann <redacted>
Sun, 1 Dec 2013 17:51:24 +0000 (18:51 +0100)
hardware/common/serial.c
libsigrok-internal.h

index 342980d0053e40694f781900ee6ccfce20a4d8ff..c131b38a24a6b46fe73d5bcfbe62ab6b51cf00de 100644 (file)
@@ -66,8 +66,8 @@ SR_PRIV int serial_open(struct sr_serial_dev_inst *serial, int flags)
                sp_flags = (SP_MODE_READ | SP_MODE_WRITE);
        else if (flags & SERIAL_RDONLY)
                sp_flags = SP_MODE_READ;
-       if (flags & SERIAL_NONBLOCK)
-               sp_flags |= SP_MODE_NONBLOCK;
+
+       serial->nonblocking = (flags & SERIAL_NONBLOCK) ? 1 : 0;
 
        ret = sp_open(serial->data, sp_flags);
 
@@ -203,7 +203,10 @@ SR_PRIV int serial_write(struct sr_serial_dev_inst *serial,
                return SR_ERR;
        }
 
-       ret = sp_write(serial->data, buf, count);
+       if (serial->nonblocking)
+               ret = sp_nonblocking_write(serial->data, buf, count);
+       else
+               ret = sp_blocking_write(serial->data, buf, count, 0);
 
        switch (ret) {
        case SP_ERR_ARG:
@@ -247,7 +250,10 @@ SR_PRIV int serial_read(struct sr_serial_dev_inst *serial, void *buf,
                return SR_ERR;
        }
 
-       ret = sp_read(serial->data, buf, count);
+       if (serial->nonblocking)
+               ret = sp_nonblocking_read(serial->data, buf, count);
+       else
+               ret = sp_blocking_read(serial->data, buf, count, 0);
 
        switch (ret) {
        case SP_ERR_ARG:
index 376e657e05c59e7d7c6617bb6dffed810bfa5015..358d555951281a7ea00304f8fafd7f3521ec873d 100644 (file)
@@ -75,6 +75,7 @@ struct sr_serial_dev_inst {
        char *port;
        char *serialcomm;
        int fd;
+       int nonblocking;
        struct sp_port *data;
 };
 #endif