]> sigrok.org Git - libsigrok.git/blobdiff - src/scpi/scpi_libgpib.c
scpi: Rephrase buffer resize for free space during SCPI read, add comments
[libsigrok.git] / src / scpi / scpi_libgpib.c
index cd098e8965ddaa531937bddf6e0192db187d7a99..cab72df720f426bfcfc9f7f19909bb9862da7e03 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <config.h>
 #include <gpib/ib.h>
 #include <string.h>
-#include "libsigrok.h"
+#include <libsigrok/libsigrok.h>
 #include "libsigrok-internal.h"
+#include "scpi.h"
 
 #define LOG_PREFIX "scpi_gpib"
 
@@ -47,9 +49,9 @@ static int scpi_gpib_dev_inst_new(void *priv, struct drv_context *drvc,
        return SR_OK;
 }
 
-static int scpi_gpib_open(void *priv)
+static int scpi_gpib_open(struct sr_scpi_dev_inst *scpi)
 {
-       struct scpi_gpib *gscpi = priv;
+       struct scpi_gpib *gscpi = scpi->priv;
 
        if ((gscpi->descriptor = ibfind(gscpi->name)) < 0)
                return SR_ERR;
@@ -82,15 +84,15 @@ static int scpi_gpib_send(void *priv, const char *command)
 
        if (ibsta & ERR)
        {
-               sr_err("Error while sending SCPI command: '%s': iberr = %d.",
-                               command, iberr);
+               sr_err("Error while sending SCPI command: '%s': iberr = %s.",
+                       command, gpib_error_string(iberr));
                return SR_ERR;
        }
 
        if (ibcnt < len)
        {
                sr_err("Failed to send all of SCPI command: '%s': "
-                               "len = %d, ibcnt = .", command, len, ibcnt);
+                               "len = %d, ibcnt = %d.", command, len, ibcnt);
                return SR_ERR;
        }
 
@@ -116,7 +118,8 @@ static int scpi_gpib_read_data(void *priv, char *buf, int maxlen)
 
        if (ibsta & ERR)
        {
-               sr_err("Error while reading SCPI response: iberr = %d.", iberr);
+               sr_err("Error while reading SCPI response: iberr = %s.",
+                       gpib_error_string(iberr));
                return SR_ERR;
        }
 
@@ -132,10 +135,13 @@ static int scpi_gpib_read_complete(void *priv)
        return gscpi->read_started && (ibsta & END);
 }
 
-static int scpi_gpib_close(void *priv)
+static int scpi_gpib_close(struct sr_scpi_dev_inst *scpi)
 {
-       struct scpi_gpib *gscpi = priv;
+       struct scpi_gpib *gscpi = scpi->priv;
 
+       /* Put device in back local mode to prevent lock-out of front panel. */
+       ibloc(gscpi->descriptor);
+       /* Now it's safe to close the handle. */
        ibonl(gscpi->descriptor, 0);
 
        return SR_OK;