X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fcommon%2Fserial.c;h=05e6f3b4eb4768c4e244582e18d7944c092b49f4;hb=066d42b1c803e3b78b7d34df1f1516f729f81085;hp=83f3281288c13afcc8fdf53fa91c6ab4766bafc7;hpb=a0dfaa6c4c34fd37e4ea5294960526145e043e4c;p=libsigrok.git diff --git a/hardware/common/serial.c b/hardware/common/serial.c index 83f32812..05e6f3b4 100644 --- a/hardware/common/serial.c +++ b/hardware/common/serial.c @@ -108,9 +108,9 @@ SR_PRIV int serial_close(struct sr_serial_dev_inst *serial) } sr_spew("Closing serial port %s (fd %d).", serial->port, serial->fd); - ret = SR_OK; ret = sp_close(serial->data); + sp_free_port(serial->data); switch (ret) { case SP_ERR_ARG: @@ -125,7 +125,7 @@ SR_PRIV int serial_close(struct sr_serial_dev_inst *serial) serial->fd = -1; - return ret; + return SR_OK; } /** @@ -166,7 +166,7 @@ SR_PRIV int serial_flush(struct sr_serial_dev_inst *serial) return SR_ERR; } - return ret; + return SR_OK; } /** @@ -176,7 +176,7 @@ SR_PRIV int serial_flush(struct sr_serial_dev_inst *serial) * @param buf Buffer containing the bytes to write. * @param count Number of bytes to write. * - * @return The number of bytes written, or -1 upon failure. + * @return The number of bytes written, or a negative error code upon failure. */ SR_PRIV int serial_write(struct sr_serial_dev_inst *serial, const void *buf, size_t count) @@ -186,13 +186,13 @@ SR_PRIV int serial_write(struct sr_serial_dev_inst *serial, if (!serial) { sr_dbg("Invalid serial port."); - return -1; + return SR_ERR; } if (serial->fd == -1) { sr_dbg("Cannot use unopened serial port %s (fd %d).", serial->port, serial->fd); - return -1; + return SR_ERR; } ret = sp_write(serial->data, buf, count); @@ -220,7 +220,7 @@ SR_PRIV int serial_write(struct sr_serial_dev_inst *serial, * @param buf Buffer where to store the bytes that are read. * @param count The number of bytes to read. * - * @return The number of bytes read, or -1 upon failure. + * @return The number of bytes read, or a negative error code upon failure. */ SR_PRIV int serial_read(struct sr_serial_dev_inst *serial, void *buf, size_t count) @@ -230,13 +230,13 @@ SR_PRIV int serial_read(struct sr_serial_dev_inst *serial, void *buf, if (!serial) { sr_dbg("Invalid serial port."); - return -1; + return SR_ERR; } if (serial->fd == -1) { sr_dbg("Cannot use unopened serial port %s (fd %d).", serial->port, serial->fd); - return -1; + return SR_ERR; } ret = sp_read(serial->data, buf, count); @@ -245,11 +245,12 @@ SR_PRIV int serial_read(struct sr_serial_dev_inst *serial, void *buf, case SP_ERR_ARG: sr_err("Attempted serial port read with invalid arguments."); return SR_ERR_ARG; - case SP_ERR_FAIL: - error = sp_last_error_message(); - sr_err("Read error: %s.", error); - sp_free_error_message(error); - return SR_ERR; + // Temporarily disabled, will come back later. + // case SP_ERR_FAIL: + // error = sp_last_error_message(); + // sr_err("Read error: %s.", error); + // sp_free_error_message(error); + // return SR_ERR; } sr_spew("Read %d/%d bytes (fd %d).", ret, count, serial->fd);