From: Uwe Hermann Date: Thu, 15 Jun 2017 17:55:15 +0000 (+0200) Subject: drivers: Use serial_write_blocking() everywhere. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=379e95c587e1d;p=libsigrok.git drivers: Use serial_write_blocking() everywhere. This fixes bug #962. --- diff --git a/src/dmm/metex14.c b/src/dmm/metex14.c index 0d7234f3..65a3f1fe 100644 --- a/src/dmm/metex14.c +++ b/src/dmm/metex14.c @@ -293,7 +293,7 @@ SR_PRIV int sr_metex14_packet_request(struct sr_serial_dev_inst *serial) sr_spew("Requesting DMM packet."); - return (serial_write_nonblocking(serial, &wbuf, 1) == 1) ? SR_OK : SR_ERR; + return serial_write_blocking(serial, &wbuf, 1, 0); } #endif diff --git a/src/hardware/cem-dt-885x/protocol.c b/src/hardware/cem-dt-885x/protocol.c index 092d1654..f6e05de9 100644 --- a/src/hardware/cem-dt-885x/protocol.c +++ b/src/hardware/cem-dt-885x/protocol.c @@ -400,7 +400,7 @@ SR_PRIV int cem_dt_885x_receive_data(int fd, int revents, void *cb_data) } else { /* Tell device to start transferring from memory. */ cmd = CMD_TRANSFER_MEMORY; - serial_write_nonblocking(serial, &cmd, 1); + serial_write_blocking(serial, &cmd, 1, 0); } } } @@ -456,7 +456,7 @@ static int cem_dt_885x_toggle(const struct sr_dev_inst *sdi, uint8_t cmd, * only thing to do is wait for the token that will confirm * whether the command worked or not, and resend if needed. */ while (TRUE) { - if (serial_write_nonblocking(serial, (const void *)&cmd, 1) != 1) + if (serial_write_blocking(serial, (const void *)&cmd, 1, 0) < 0) return SR_ERR; if (wait_for_token(sdi, tokens, timeout) == SR_ERR) return SR_ERR; @@ -817,7 +817,7 @@ SR_PRIV int cem_dt_885x_power_off(const struct sr_dev_inst *sdi) cmd = CMD_TOGGLE_POWER_OFF; while (TRUE) { serial_flush(serial); - if (serial_write_nonblocking(serial, (const void *)&cmd, 1) != 1) + if (serial_write_blocking(serial, (const void *)&cmd, 1, 0) < 0) return SR_ERR; /* It never takes more than 23ms for the next token to arrive. */ g_usleep(25 * 1000); diff --git a/src/hardware/kern-scale/api.c b/src/hardware/kern-scale/api.c index dea9c352..e369a44c 100644 --- a/src/hardware/kern-scale/api.c +++ b/src/hardware/kern-scale/api.c @@ -82,7 +82,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) serial_flush(serial); sr_spew("Set O1 mode (continuous values, stable and unstable ones)."); - if (serial_write_nonblocking(serial, "O1\r\n", 4) != 4) + if (serial_write_blocking(serial, "O1\r\n", 4, 0) < 0) goto scan_cleanup; /* Device replies with "A00\r\n" (OK) or "E01\r\n" (Error). Ignore. */ @@ -140,7 +140,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) serial = sdi->conn; sr_spew("Set O1 mode (continuous values, stable and unstable ones)."); - if (serial_write_nonblocking(serial, "O1\r\n", 4) != 4) + if (serial_write_blocking(serial, "O1\r\n", 4, 0) < 0) return SR_ERR; /* Device replies with "A00\r\n" (OK) or "E01\r\n" (Error). Ignore. */ diff --git a/src/hardware/pce-322a/protocol.c b/src/hardware/pce-322a/protocol.c index 90c1986b..564f2984 100644 --- a/src/hardware/pce-322a/protocol.c +++ b/src/hardware/pce-322a/protocol.c @@ -32,10 +32,7 @@ static int send_command(const struct sr_dev_inst *sdi, uint16_t command) if (!(serial = sdi->conn)) return SR_ERR; - if (serial_write_nonblocking(serial, (const void *)buffer, 2) != 2) - return SR_ERR; - - return SR_OK; + return serial_write_blocking(serial, (const void *)buffer, 2, 0); } static int send_long_command(const struct sr_dev_inst *sdi, uint32_t command) @@ -51,10 +48,7 @@ static int send_long_command(const struct sr_dev_inst *sdi, uint32_t command) if (!(serial = sdi->conn)) return SR_ERR; - if (serial_write_nonblocking(serial, (const void *)buffer, 4) != 4) - return SR_ERR; - - return SR_OK; + return serial_write_blocking(serial, (const void *)buffer, 4, 0); } static void send_data(const struct sr_dev_inst *sdi, float sample) diff --git a/src/modbus/modbus_serial_rtu.c b/src/modbus/modbus_serial_rtu.c index 21205d94..ae76e7cf 100644 --- a/src/modbus/modbus_serial_rtu.c +++ b/src/modbus/modbus_serial_rtu.c @@ -109,18 +109,18 @@ static int modbus_serial_rtu_send(void *priv, uint8_t slave_addr = modbus->slave_addr; uint16_t crc; - result = serial_write_nonblocking(serial, &slave_addr, sizeof(slave_addr)); + result = serial_write_blocking(serial, &slave_addr, sizeof(slave_addr), 0); if (result < 0) return result; - result = serial_write_nonblocking(serial, buffer, buffer_size); + result = serial_write_blocking(serial, buffer, buffer_size, 0); if (result < 0) return result; crc = modbus_serial_rtu_crc(0xFFFF, &slave_addr, sizeof(slave_addr)); crc = modbus_serial_rtu_crc(crc, buffer, buffer_size); - result = serial_write_nonblocking(serial, &crc, sizeof(crc)); + result = serial_write_blocking(serial, &crc, sizeof(crc), 0); if (result < 0) return result; diff --git a/src/scpi/scpi_serial.c b/src/scpi/scpi_serial.c index 6c4e63c7..464924ce 100644 --- a/src/scpi/scpi_serial.c +++ b/src/scpi/scpi_serial.c @@ -117,20 +117,14 @@ static int scpi_serial_source_remove(struct sr_session *session, void *priv) static int scpi_serial_send(void *priv, const char *command) { - int len, result, written; + int result; struct scpi_serial *sscpi = priv; struct sr_serial_dev_inst *serial = sscpi->serial; - len = strlen(command); - written = 0; - while (written < len) { - result = serial_write_nonblocking(serial, - command + written, len - written); - if (result < 0) { - sr_err("Error while sending SCPI command: '%s'.", command); - return SR_ERR; - } - written += result; + result = serial_write_blocking(serial, command, strlen(command), 0); + if (result < 0) { + sr_err("Error while sending SCPI command: '%s'.", command); + return SR_ERR; } sr_spew("Successfully sent SCPI command: '%s'.", command);