From: Martin Ling Date: Sun, 28 Sep 2014 11:54:56 +0000 (+0100) Subject: Fix similar broken error handling on several serial calls. X-Git-Tag: libsigrok-0.4.0~895 X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=081c214eace0c9088cbcbd9a3d448f6fac5e98f4 Fix similar broken error handling on several serial calls. --- diff --git a/src/hardware/agilent-dmm/api.c b/src/hardware/agilent-dmm/api.c index e4240e62..b7ae7fb2 100644 --- a/src/hardware/agilent-dmm/api.c +++ b/src/hardware/agilent-dmm/api.c @@ -116,9 +116,8 @@ static GSList *scan(GSList *options) return NULL; serial_flush(serial); - if (serial_write_blocking(serial, "*IDN?\r\n", 7) == -1) { - sr_err("Unable to send identification string: %s.", - strerror(errno)); + if (serial_write_blocking(serial, "*IDN?\r\n", 7) < 7) { + sr_err("Unable to send identification string."); return NULL; } diff --git a/src/hardware/agilent-dmm/sched.c b/src/hardware/agilent-dmm/sched.c index df651134..b555cd8b 100644 --- a/src/hardware/agilent-dmm/sched.c +++ b/src/hardware/agilent-dmm/sched.c @@ -140,8 +140,8 @@ static int agdmm_send(const struct sr_dev_inst *sdi, const char *cmd) strcat(buf, "\r\n"); else strcat(buf, "\n\r\n"); - if (serial_write_blocking(serial, buf, strlen(buf)) == -1) { - sr_err("Failed to send: %s.", strerror(errno)); + if (serial_write_blocking(serial, buf, strlen(buf)) < strlen(buf)) { + sr_err("Failed to send."); return SR_ERR; } diff --git a/src/hardware/atten-pps3xxx/api.c b/src/hardware/atten-pps3xxx/api.c index 75a1fbbd..a0f84152 100644 --- a/src/hardware/atten-pps3xxx/api.c +++ b/src/hardware/atten-pps3xxx/api.c @@ -130,9 +130,8 @@ static GSList *scan(GSList *options, int modelid) memset(packet, 0, PACKET_SIZE); packet[0] = 0xaa; packet[1] = 0xaa; - if (serial_write_blocking(serial, packet, PACKET_SIZE) == -1) { - sr_err("Unable to write while probing for hardware: %s", - strerror(errno)); + if (serial_write_blocking(serial, packet, PACKET_SIZE) < PACKET_SIZE) { + sr_err("Unable to write while probing for hardware."); return NULL; } /* The device responds with a 24-byte packet when it receives a packet. diff --git a/src/hardware/atten-pps3xxx/protocol.c b/src/hardware/atten-pps3xxx/protocol.c index 66ecb7a2..95137d2e 100644 --- a/src/hardware/atten-pps3xxx/protocol.c +++ b/src/hardware/atten-pps3xxx/protocol.c @@ -86,8 +86,8 @@ SR_PRIV void send_packet(const struct sr_dev_inst *sdi, uint8_t *packet) struct sr_serial_dev_inst *serial; serial = sdi->conn; - if (serial_write_blocking(serial, packet, PACKET_SIZE) == -1) - sr_dbg("Failed to send packet: %s", strerror(errno)); + if (serial_write_blocking(serial, packet, PACKET_SIZE) < PACKET_SIZE) + sr_dbg("Failed to send packet."); dump_packet("sent", packet); } diff --git a/src/hardware/colead-slm/protocol.c b/src/hardware/colead-slm/protocol.c index 6b89ea14..6864cb68 100644 --- a/src/hardware/colead-slm/protocol.c +++ b/src/hardware/colead-slm/protocol.c @@ -207,8 +207,8 @@ SR_PRIV int colead_slm_receive_data(int fd, int revents, void *cb_data) * we don't want it. */ return TRUE; /* Got 0x10, "measurement ready". */ - if (serial_write_blocking(serial, "\x20", 1) == -1) - sr_err("unable to send command: %s", strerror(errno)); + if (serial_write_blocking(serial, "\x20", 1) < 1) + sr_err("unable to send command"); else { devc->state = COMMAND_SENT; devc->buflen = 0; diff --git a/src/hardware/conrad-digi-35-cpu/protocol.c b/src/hardware/conrad-digi-35-cpu/protocol.c index cfabdc7b..6b1d0d56 100644 --- a/src/hardware/conrad-digi-35-cpu/protocol.c +++ b/src/hardware/conrad-digi-35-cpu/protocol.c @@ -48,8 +48,8 @@ SR_PRIV int send_msg1(const struct sr_dev_inst *sdi, char cmd, int param) sr_spew("send_msg1(): %c%c%c%c\\r", buf[0], buf[1], buf[2], buf[3]); - if (serial_write_blocking(serial, buf, sizeof(buf)) == -1) { - sr_err("Write error for cmd=%c: %d %s", cmd, errno, strerror(errno)); + if (serial_write_blocking(serial, buf, sizeof(buf)) < sizeof(buf)) { + sr_err("Write error for cmd=%c", cmd); return SR_ERR; } diff --git a/src/hardware/gmc-mh-1x-2x/protocol.c b/src/hardware/gmc-mh-1x-2x/protocol.c index cfcbc4dc..3ba4f4ff 100644 --- a/src/hardware/gmc-mh-1x-2x/protocol.c +++ b/src/hardware/gmc-mh-1x-2x/protocol.c @@ -1307,7 +1307,7 @@ int req_meas14(const struct sr_dev_inst *sdi) devc->cmd_idx = 0; create_cmd_14(devc->addr, 8, params, msg); devc->req_sent_at = g_get_monotonic_time(); - if (serial_write_blocking(serial, msg, sizeof(msg)) == -1) { + if (serial_write_blocking(serial, msg, sizeof(msg)) < sizeof(msg)) { return SR_ERR; } @@ -1350,7 +1350,7 @@ int req_stat14(const struct sr_dev_inst *sdi, gboolean power_on) /* Write message and wait for reply */ devc->req_sent_at = g_get_monotonic_time(); - if (serial_write_blocking(serial, msg, sizeof(msg)) == -1) { + if (serial_write_blocking(serial, msg, sizeof(msg)) < sizeof(msg)) { return SR_ERR; }