From: Martin Ling Date: Sat, 7 Dec 2013 16:11:27 +0000 (+0000) Subject: scpi_serial: Iterate serial_write as necessary to send full commands. X-Git-Tag: libsigrok-0.3.0~464 X-Git-Url: https://sigrok.org/gitweb/?a=commitdiff_plain;h=721fc2272ea1e7f3036eca570380bafe40146859;p=libsigrok.git scpi_serial: Iterate serial_write as necessary to send full commands. --- diff --git a/hardware/common/scpi_serial.c b/hardware/common/scpi_serial.c index e89e7f71..0b1e30d8 100644 --- a/hardware/common/scpi_serial.c +++ b/hardware/common/scpi_serial.c @@ -65,21 +65,25 @@ SR_PRIV int scpi_serial_source_remove(void *priv) SR_PRIV int scpi_serial_send(void *priv, const char *command) { - int len, out; + int len, result, written; gchar *terminated_command; struct sr_serial_dev_inst *serial = priv; terminated_command = g_strconcat(command, "\n", NULL); len = strlen(terminated_command); - out = serial_write(serial, terminated_command, len); - g_free(terminated_command); - - if (out != len) { - sr_dbg("Only sent %d/%d bytes of SCPI command: '%s'.", out, - len, command); - return SR_ERR; + written = 0; + while (written < len) { + result = serial_write(serial, terminated_command + written, len - written); + if (result < 0) { + sr_err("Error while sending SCPI command: '%s'.", command); + g_free(terminated_command); + return SR_ERR; + } + written += result; } + g_free(terminated_command); + sr_spew("Successfully sent SCPI command: '%s'.", command); return SR_OK;