scpi_serial: Iterate serial_write as necessary to send full commands.
This commit is contained in:
parent
bb9d6116f8
commit
721fc2272e
|
@ -65,21 +65,25 @@ SR_PRIV int scpi_serial_source_remove(void *priv)
|
||||||
|
|
||||||
SR_PRIV int scpi_serial_send(void *priv, const char *command)
|
SR_PRIV int scpi_serial_send(void *priv, const char *command)
|
||||||
{
|
{
|
||||||
int len, out;
|
int len, result, written;
|
||||||
gchar *terminated_command;
|
gchar *terminated_command;
|
||||||
struct sr_serial_dev_inst *serial = priv;
|
struct sr_serial_dev_inst *serial = priv;
|
||||||
|
|
||||||
terminated_command = g_strconcat(command, "\n", NULL);
|
terminated_command = g_strconcat(command, "\n", NULL);
|
||||||
len = strlen(terminated_command);
|
len = strlen(terminated_command);
|
||||||
out = serial_write(serial, terminated_command, len);
|
written = 0;
|
||||||
g_free(terminated_command);
|
while (written < len) {
|
||||||
|
result = serial_write(serial, terminated_command + written, len - written);
|
||||||
if (out != len) {
|
if (result < 0) {
|
||||||
sr_dbg("Only sent %d/%d bytes of SCPI command: '%s'.", out,
|
sr_err("Error while sending SCPI command: '%s'.", command);
|
||||||
len, command);
|
g_free(terminated_command);
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
|
}
|
||||||
|
written += result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_free(terminated_command);
|
||||||
|
|
||||||
sr_spew("Successfully sent SCPI command: '%s'.", command);
|
sr_spew("Successfully sent SCPI command: '%s'.", command);
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
|
|
Loading…
Reference in New Issue