From: Sven Schnelle Date: Mon, 13 Feb 2017 17:48:52 +0000 (+0100) Subject: SCPI: add sr_scpi_write_data() X-Git-Tag: libsigrok-0.5.0~88 X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=b6be55ce95b8d4d00d64874a05c022846e43cec4;hp=9a512113ca0cfb34e8a12c678573e3687590ab41 SCPI: add sr_scpi_write_data() Can be used to send raw data on a SCPI connection. Signed-off-by: Sven Schnelle --- diff --git a/src/scpi.h b/src/scpi.h index ddfd9450..93230062 100644 --- a/src/scpi.h +++ b/src/scpi.h @@ -91,6 +91,7 @@ struct sr_scpi_dev_inst { int (*send)(void *priv, const char *command); int (*read_begin)(void *priv); int (*read_data)(void *priv, char *buf, int maxlen); + int (*write_data)(void *priv, char *buf, int len); int (*read_complete)(void *priv); int (*close)(struct sr_scpi_dev_inst *scpi); void (*free)(void *priv); @@ -116,6 +117,7 @@ SR_PRIV int sr_scpi_send_variadic(struct sr_scpi_dev_inst *scpi, const char *format, va_list args); SR_PRIV int sr_scpi_read_begin(struct sr_scpi_dev_inst *scpi); SR_PRIV int sr_scpi_read_data(struct sr_scpi_dev_inst *scpi, char *buf, int maxlen); +SR_PRIV int sr_scpi_write_data(struct sr_scpi_dev_inst *scpi, char *buf, int len); SR_PRIV int sr_scpi_read_complete(struct sr_scpi_dev_inst *scpi); SR_PRIV int sr_scpi_close(struct sr_scpi_dev_inst *scpi); SR_PRIV void sr_scpi_free(struct sr_scpi_dev_inst *scpi); diff --git a/src/scpi/scpi.c b/src/scpi/scpi.c index 00f4ef80..48e6a484 100644 --- a/src/scpi/scpi.c +++ b/src/scpi/scpi.c @@ -337,6 +337,21 @@ SR_PRIV int sr_scpi_read_data(struct sr_scpi_dev_inst *scpi, return scpi->read_data(scpi->priv, buf, maxlen); } +/** + * Send data to SCPI device. + * + * @param scpi Previously initialised SCPI device structure. + * @param buf Buffer with data to send. + * @param len Number of bytes to send. + * + * @return Number of bytes read, or SR_ERR upon failure. + */ +SR_PRIV int sr_scpi_write_data(struct sr_scpi_dev_inst *scpi, + char *buf, int maxlen) +{ + return scpi->write_data(scpi->priv, buf, maxlen); +} + /** * Check whether a complete SCPI response has been received. * diff --git a/src/scpi/scpi_tcp.c b/src/scpi/scpi_tcp.c index a4cb6942..c01cc560 100644 --- a/src/scpi/scpi_tcp.c +++ b/src/scpi/scpi_tcp.c @@ -183,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; @@ -256,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,