va_end(args_copy);
/* Allocate buffer and write out command. */
- buf = g_malloc(len + 1);
+ buf = g_malloc0(len + 2);
vsprintf(buf, format, args);
+ if (buf[len - 1] != '\n')
+ buf[len] = '\n';
/* Send command. */
ret = scpi->send(scpi->priv, buf);
static int scpi_serial_send(void *priv, const char *command)
{
int len, result, written;
- gchar *terminated_command;
struct scpi_serial *sscpi = priv;
struct sr_serial_dev_inst *serial = sscpi->serial;
- terminated_command = g_strconcat(command, "\n", NULL);
- len = strlen(terminated_command);
+ len = strlen(command);
written = 0;
while (written < len) {
result = serial_write_nonblocking(serial,
- terminated_command + written, len - written);
+ 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;
{
struct scpi_tcp *tcp = priv;
int len, out;
- char *terminated_command;
- terminated_command = g_strdup_printf("%s\r\n", command);
- len = strlen(terminated_command);
- out = send(tcp->socket, terminated_command, len, 0);
- g_free(terminated_command);
+ len = strlen(command);
+ out = send(tcp->socket, command, len, 0);
if (out < 0) {
sr_err("Send error: %s", g_strerror(errno));
static int scpi_visa_send(void *priv, const char *command)
{
struct scpi_visa *vscpi = priv;
- gchar *terminated_command;
ViUInt32 written = 0;
int len;
- terminated_command = g_strconcat(command, "\n", NULL);
- len = strlen(terminated_command);
- if (viWrite(vscpi->vi, (ViBuf) (terminated_command + written), len,
+ len = strlen(command);
+ if (viWrite(vscpi->vi, (ViBuf) (command + written), len,
&written) != VI_SUCCESS) {
sr_err("Error while sending SCPI command: '%s'.", command);
- g_free(terminated_command);
return SR_ERR;
}
- g_free(terminated_command);
-
sr_spew("Successfully sent SCPI command: '%s'.", command);
return SR_OK;
struct scpi_vxi *vxi = priv;
Device_WriteResp *write_resp;
Device_WriteParms write_parms;
- char *terminated_command;
unsigned long len;
- terminated_command = g_strdup_printf("%s\r\n", command);
- len = strlen(terminated_command);
+ len = strlen(command);
write_parms.lid = vxi->link;
write_parms.io_timeout = VXI_DEFAULT_TIMEOUT_MS;
write_parms.lock_timeout = VXI_DEFAULT_TIMEOUT_MS;
write_parms.flags = DF_END;
write_parms.data.data_len = MIN(len, vxi->max_send_size);
- write_parms.data.data_val = terminated_command;
+ write_parms.data.data_val = command;
if (!(write_resp = device_write_1(&write_parms, vxi->client))
|| write_resp->error) {
return SR_ERR;
}
- g_free(terminated_command);
-
if (write_resp->size < len)
sr_dbg("Only sent %lu/%lu bytes of SCPI command: '%s'.",
write_resp->size, len, command);