SCPI: add sr_scpi_write_data()

Can be used to send raw data on a SCPI connection.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
This commit is contained in:
Sven Schnelle 2017-02-13 18:48:52 +01:00 committed by Uwe Hermann
parent 9a512113ca
commit b6be55ce95
3 changed files with 33 additions and 0 deletions

View File

@ -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);

View File

@ -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.
*

View File

@ -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,