From: Martin Ling Date: Tue, 3 Dec 2013 22:56:32 +0000 (+0000) Subject: Add sr_scpi_read() operation for reading arbitrary data. X-Git-Tag: libsigrok-0.3.0~496 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=a1ff9c1897262faa3b284ea5bb82593c45de70d0;p=libsigrok.git Add sr_scpi_read() operation for reading arbitrary data. --- diff --git a/hardware/common/scpi.c b/hardware/common/scpi.c index f8810a59..0091ba34 100644 --- a/hardware/common/scpi.c +++ b/hardware/common/scpi.c @@ -146,6 +146,21 @@ SR_PRIV int sr_scpi_receive(struct sr_scpi_dev_inst *scpi, return scpi->receive(scpi->priv, scpi_response); } +/** + * Read part of a response from SCPI device. + * + * @param scpi Previously initialised SCPI device structure. + * @param buf Buffer to store result. + * @param maxlen Maximum number of bytes to read. + * + * @return Number of bytes read, or SR_ERR upon failure. + */ +SR_PRIV int sr_scpi_read(struct sr_scpi_dev_inst *scpi, + char *buf, int maxlen) +{ + return scpi->read(scpi->priv, buf, maxlen); +} + /** * Close SCPI device. * diff --git a/hardware/common/scpi_serial.c b/hardware/common/scpi_serial.c index cbe51b05..3e149252 100644 --- a/hardware/common/scpi_serial.c +++ b/hardware/common/scpi_serial.c @@ -151,6 +151,7 @@ SR_PRIV struct sr_scpi_dev_inst *scpi_serial_dev_inst_new(const char *port, scpi->source_remove = scpi_serial_source_remove; scpi->send = scpi_serial_send; scpi->receive = scpi_serial_receive; + scpi->read = serial_read; scpi->close = serial_close; scpi->free = sr_serial_dev_inst_free; scpi->priv = serial; diff --git a/hardware/common/scpi_usbtmc.c b/hardware/common/scpi_usbtmc.c index e4c10be6..f7f0958e 100644 --- a/hardware/common/scpi_usbtmc.c +++ b/hardware/common/scpi_usbtmc.c @@ -111,6 +111,21 @@ SR_PRIV int scpi_usbtmc_receive(void *priv, char **scpi_response) return SR_OK; } +SR_PRIV int scpi_usbtmc_read(void *priv, unsigned char *buf, int maxlen) +{ + struct sr_usbtmc_dev_inst *usbtmc = priv; + int len; + + len = read(usbtmc->fd, buf, maxlen); + + if (len < 0) { + sr_err("Read error: %s", strerror(errno)); + return SR_ERR; + } + + return len; +} + SR_PRIV int scpi_usbtmc_close(void *priv) { struct sr_usbtmc_dev_inst *usbtmc = priv; @@ -139,6 +154,7 @@ SR_PRIV struct sr_scpi_dev_inst *scpi_usbtmc_dev_inst_new(const char *device) scpi->source_remove = scpi_usbtmc_source_remove; scpi->send = scpi_usbtmc_send; scpi->receive = scpi_usbtmc_receive; + scpi->read = scpi_usbtmc_read; scpi->close = scpi_usbtmc_close; scpi->free = sr_usbtmc_dev_inst_free; scpi->priv = usbtmc; diff --git a/libsigrok-internal.h b/libsigrok-internal.h index 0457c509..59359f0c 100644 --- a/libsigrok-internal.h +++ b/libsigrok-internal.h @@ -292,6 +292,7 @@ struct sr_scpi_dev_inst { int (*source_remove)(void *priv); int (*send)(void *priv, const char *command); int (*receive)(void *priv, char **scpi_response); + int (*read)(void *priv, char *buf, int maxlen); int (*close)(void *priv); void (*free)(void *priv); void *priv; @@ -305,6 +306,7 @@ SR_PRIV int sr_scpi_send(struct sr_scpi_dev_inst *scpi, const char *command); SR_PRIV int sr_scpi_receive(struct sr_scpi_dev_inst *scpi, char **scpi_response); +SR_PRIV int sr_scpi_read(struct sr_scpi_dev_inst *scpi, char *buf, int maxlen); SR_PRIV int sr_scpi_close(struct sr_scpi_dev_inst *scpi); SR_PRIV void sr_scpi_free(struct sr_scpi_dev_inst *scpi);