X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=blobdiff_plain;f=src%2Fscpi%2Fscpi_tcp.c;h=c01cc5606f62a57a627fd5c895a230cb262d294c;hp=43b7a78afdf7b503b22c76c748b68bce892785af;hb=b6be55ce95b8d4d00d64874a05c022846e43cec4;hpb=6ec6c43b4738dbc7091f4a49a4ec80ea6102cb52 diff --git a/src/scpi/scpi_tcp.c b/src/scpi/scpi_tcp.c index 43b7a78a..c01cc560 100644 --- a/src/scpi/scpi_tcp.c +++ b/src/scpi/scpi_tcp.c @@ -66,15 +66,15 @@ static int scpi_tcp_dev_inst_new(void *priv, struct drv_context *drvc, } tcp->address = g_strdup(params[1]); - tcp->port = g_strdup(params[2]); - tcp->socket = -1; + tcp->port = g_strdup(params[2]); + tcp->socket = -1; return SR_OK; } -static int scpi_tcp_open(void *priv) +static int scpi_tcp_open(struct sr_scpi_dev_inst *scpi) { - struct scpi_tcp *tcp = priv; + struct scpi_tcp *tcp = scpi->priv; struct addrinfo hints; struct addrinfo *results, *res; int err; @@ -135,12 +135,9 @@ static int scpi_tcp_send(void *priv, const char *command) { 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)); @@ -186,6 +183,21 @@ static int scpi_tcp_raw_read_data(void *priv, char *buf, int maxlen) return len; } +static int scpi_tcp_raw_write_data(void *priv, char *buf, int len) +{ + struct scpi_tcp *tcp = priv; + int sentlen; + + sentlen = send(tcp->socket, buf, len, 0); + + if (sentlen < 0) { + sr_err("Send error: %s.", g_strerror(errno)); + return SR_ERR; + } + + return sentlen; +} + static int scpi_tcp_rigol_read_data(void *priv, char *buf, int maxlen) { struct scpi_tcp *tcp = priv; @@ -230,9 +242,9 @@ static int scpi_tcp_read_complete(void *priv) tcp->response_bytes_read >= tcp->response_length); } -static int scpi_tcp_close(void *priv) +static int scpi_tcp_close(struct sr_scpi_dev_inst *scpi) { - struct scpi_tcp *tcp = priv; + struct scpi_tcp *tcp = scpi->priv; if (close(tcp->socket) < 0) return SR_ERR; @@ -259,6 +271,7 @@ SR_PRIV const struct sr_scpi_dev_inst scpi_tcp_raw_dev = { .send = scpi_tcp_send, .read_begin = scpi_tcp_read_begin, .read_data = scpi_tcp_raw_read_data, + .write_data = scpi_tcp_raw_write_data, .read_complete = scpi_tcp_read_complete, .close = scpi_tcp_close, .free = scpi_tcp_free,