aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/scpi.h2
-rw-r--r--src/scpi/scpi.c15
-rw-r--r--src/scpi/scpi_tcp.c16
3 files changed, 33 insertions, 0 deletions
diff --git a/src/scpi.h b/src/scpi.h
index ddfd945..9323006 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 00f4ef8..48e6a48 100644
--- a/src/scpi/scpi.c
+++ b/src/scpi/scpi.c
@@ -338,6 +338,21 @@ SR_PRIV int sr_scpi_read_data(struct sr_scpi_dev_inst *scpi,
}
/**
+ * 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.
*
* @param scpi Previously initialised SCPI device structure.
diff --git a/src/scpi/scpi_tcp.c b/src/scpi/scpi_tcp.c
index a4cb694..c01cc56 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,