]> sigrok.org Git - libsigrok.git/commitdiff
drivers: Use serial_write_blocking() everywhere.
authorUwe Hermann <redacted>
Thu, 15 Jun 2017 17:55:15 +0000 (19:55 +0200)
committerUwe Hermann <redacted>
Mon, 7 Aug 2017 12:22:52 +0000 (14:22 +0200)
This fixes bug #962.

src/dmm/metex14.c
src/hardware/cem-dt-885x/protocol.c
src/hardware/kern-scale/api.c
src/hardware/pce-322a/protocol.c
src/modbus/modbus_serial_rtu.c
src/scpi/scpi_serial.c

index 0d7234f36748da95e378a977b165aae93087c199..65a3f1fe78a481c47509ab33c1a701dac216cd26 100644 (file)
@@ -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
 
index 092d16542aa2aa1e0f3ff75c7049dac726228cc8..f6e05de9693845aee20dfb30e3508fd3f474b254 100644 (file)
@@ -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);
index dea9c35291ccbf2b202ceb5fc46df9b675ebd74a..e369a44cf5e585722dbec8acf544b8a90b8119e8 100644 (file)
@@ -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. */
 
index 90c1986b69e1b9a18dadbaa02fe509fe3f400038..564f2984de50cbc5574d174fa21ca4cf2be8837a 100644 (file)
@@ -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)
index 21205d941163d6544602e66b44a9d90d5f73fabc..ae76e7cf769edf2e14c7dd3d8489ab44467c521a 100644 (file)
@@ -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;
 
index 6c4e63c7b9122756c7bfaaf2983d9e80203f4489..464924ce3086f2253c034339d22b0830917a5ce8 100644 (file)
@@ -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);