drivers: Use serial_write_blocking() everywhere.

This fixes bug #962.
This commit is contained in:
Uwe Hermann 2017-06-15 19:55:15 +02:00
parent b5df922e4f
commit 379e95c587
6 changed files with 16 additions and 28 deletions

View 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

View 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);

View 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. */

View 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)

View 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;

View 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);