X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fscpi%2Fscpi_libgpib.c;h=5c82bd6f3dee6edd2e27a25292d16667d10fad27;hb=9417f26fd47556c4b4f6ecaa08a2860672664eb9;hp=5df90413ff4dd1197e9475419a4f03537721bc31;hpb=7343ad1ec72860b5d11ca8f35c4d014a1fa5b643;p=libsigrok.git
diff --git a/src/scpi/scpi_libgpib.c b/src/scpi/scpi_libgpib.c
index 5df90413..5c82bd6f 100644
--- a/src/scpi/scpi_libgpib.c
+++ b/src/scpi/scpi_libgpib.c
@@ -17,11 +17,12 @@
* along with this program. If not, see .
*/
-#include "libsigrok.h"
-#include "libsigrok-internal.h"
-
+#include
#include
#include
+#include
+#include "libsigrok-internal.h"
+#include "scpi.h"
#define LOG_PREFIX "scpi_gpib"
@@ -48,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;
@@ -58,6 +59,16 @@ static int scpi_gpib_open(void *priv)
return SR_OK;
}
+static int scpi_gpib_connection_id(struct sr_scpi_dev_inst *scpi,
+ char **connection_id)
+{
+ struct scpi_gpib *gscpi = scpi->priv;
+
+ *connection_id = g_strdup_printf("%s/%s", scpi->prefix, gscpi->name);
+
+ return SR_OK;
+}
+
static int scpi_gpib_source_add(struct sr_session *session, void *priv,
int events, int timeout, sr_receive_data_callback cb, void *cb_data)
{
@@ -83,15 +94,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;
}
@@ -117,7 +128,9 @@ 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, ibsta = %d.",
+ gpib_error_string(iberr), ibsta);
return SR_ERR;
}
@@ -133,10 +146,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;
@@ -149,18 +165,39 @@ static void scpi_gpib_free(void *priv)
g_free(gscpi->name);
}
+SR_PRIV int sr_scpi_gpib_spoll(struct sr_scpi_dev_inst *scpi, char *buf)
+{
+ struct scpi_gpib *gscpi = scpi->priv;
+
+ g_mutex_lock(&scpi->scpi_mutex);
+ ibrsp(gscpi->descriptor, buf);
+
+ if (ibsta & ERR) {
+ sr_err("Error while serial polling: iberr = %s.",
+ gpib_error_string(iberr));
+ g_mutex_unlock(&scpi->scpi_mutex);
+ return SR_ERR;
+ }
+ g_mutex_unlock(&scpi->scpi_mutex);
+ sr_spew("Successful serial poll: 0x%x", (uint8_t)buf[0]);
+
+ return SR_OK;
+}
+
SR_PRIV const struct sr_scpi_dev_inst scpi_libgpib_dev = {
- .name = "GPIB",
- .prefix = "libgpib",
- .priv_size = sizeof(struct scpi_gpib),
- .dev_inst_new = scpi_gpib_dev_inst_new,
- .open = scpi_gpib_open,
- .source_add = scpi_gpib_source_add,
+ .name = "GPIB",
+ .prefix = "libgpib",
+ .transport = SCPI_TRANSPORT_LIBGPIB,
+ .priv_size = sizeof(struct scpi_gpib),
+ .dev_inst_new = scpi_gpib_dev_inst_new,
+ .open = scpi_gpib_open,
+ .connection_id = scpi_gpib_connection_id,
+ .source_add = scpi_gpib_source_add,
.source_remove = scpi_gpib_source_remove,
- .send = scpi_gpib_send,
- .read_begin = scpi_gpib_read_begin,
- .read_data = scpi_gpib_read_data,
+ .send = scpi_gpib_send,
+ .read_begin = scpi_gpib_read_begin,
+ .read_data = scpi_gpib_read_data,
.read_complete = scpi_gpib_read_complete,
- .close = scpi_gpib_close,
- .free = scpi_gpib_free,
+ .close = scpi_gpib_close,
+ .free = scpi_gpib_free,
};