From: Martin Ling Date: Wed, 27 Nov 2013 01:43:49 +0000 (+0000) Subject: Use new libserialport blocking/nonblocking API calls. X-Git-Tag: libsigrok-0.3.0~518 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=9647ce694b1f76cc7196420bb9932e4ff6c8b349;p=libsigrok.git Use new libserialport blocking/nonblocking API calls. --- diff --git a/hardware/common/serial.c b/hardware/common/serial.c index 342980d0..c131b38a 100644 --- a/hardware/common/serial.c +++ b/hardware/common/serial.c @@ -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: diff --git a/libsigrok-internal.h b/libsigrok-internal.h index 376e657e..358d5559 100644 --- a/libsigrok-internal.h +++ b/libsigrok-internal.h @@ -75,6 +75,7 @@ struct sr_serial_dev_inst { char *port; char *serialcomm; int fd; + int nonblocking; struct sp_port *data; }; #endif