]> sigrok.org Git - libsigrok.git/commitdiff
Add sr_scpi_read() operation for reading arbitrary data.
authorMartin Ling <redacted>
Tue, 3 Dec 2013 22:56:32 +0000 (22:56 +0000)
committerMartin Ling <redacted>
Tue, 3 Dec 2013 23:18:37 +0000 (23:18 +0000)
hardware/common/scpi.c
hardware/common/scpi_serial.c
hardware/common/scpi_usbtmc.c
libsigrok-internal.h

index f8810a59250bfebe12666754bd76d987b7409448..0091ba3418eeacce3460a2ebd0148e079038163a 100644 (file)
@@ -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.
  *
index cbe51b059fa7519aeb5584ed835c9ef6f947376d..3e1492522aea9ee36f8a6264128b54266a5e7a08 100644 (file)
@@ -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;
index e4c10be67a0cf2e5592ad6f1f5aa5aeeed473dbc..f7f0958eadeb9bcce3f3e6207d149f0d5c408726 100644 (file)
@@ -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;
index 0457c509245dd5b558a897965064ca552747d459..59359f0cdfc44448c722f4e6962fff47230aa65d 100644 (file)
@@ -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);