From: Frank Stettner Date: Fri, 1 Feb 2019 11:18:46 +0000 (+0100) Subject: hp-3478a: Check via GPIB serial poll if new data is available. X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=02d4db356287ca58e0d8cc624199280ad91ee15c hp-3478a: Check via GPIB serial poll if new data is available. When just reading the data without check, the bus is blocked until new data is available. --- diff --git a/src/hardware/hp-3478a/protocol.c b/src/hardware/hp-3478a/protocol.c index 3ddce588..6767bf0a 100644 --- a/src/hardware/hp-3478a/protocol.c +++ b/src/hardware/hp-3478a/protocol.c @@ -406,6 +406,7 @@ SR_PRIV int hp_3478a_receive_data(int fd, int revents, void *cb_data) struct sr_scpi_dev_inst *scpi; struct sr_dev_inst *sdi; struct dev_context *devc; + char status_register; (void)fd; (void)revents; @@ -416,18 +417,28 @@ SR_PRIV int hp_3478a_receive_data(int fd, int revents, void *cb_data) scpi = sdi->conn; /* - * This is necessary to get the actual range for the encoding digits. - * When SPoll is implemmented, this can be done via SPoll. + * TODO: Wait for SRQ from the DMM when a new measurement is available. + * For now, we don't wait for a SRQ, but just do a SPoll and + * check the Data Ready bit (0x01). + * This is necessary, because (1) reading a value will block the + * bus until a measurement is available and (2) when switching + * ranges, there could be a timeout. */ - if (hp_3478a_get_status_bytes(sdi) != SR_OK) + if (sr_scpi_gpib_spoll(scpi, &status_register) != SR_OK) + return FALSE; + if (!(((uint8_t)status_register) & 0x01)) + return TRUE; + + /* Get a reading from the DMM. */ + if (sr_scpi_get_double(scpi, NULL, &devc->measurement) != SR_OK) return FALSE; /* - * TODO: Implement GPIB-SPoll, to get notified by a SRQ when a new - * measurement is available. This is necessary, because when - * switching ranges, there could be a timeout. + * This is necessary to get the actual range for the encoding digits. + * Must be called after reading the value, because it resets the + * status register! */ - if (sr_scpi_get_double(scpi, NULL, &devc->measurement) != SR_OK) + if (hp_3478a_get_status_bytes(sdi) != SR_OK) return FALSE; acq_send_measurement(sdi); diff --git a/src/scpi.h b/src/scpi.h index 13b2d301..eeee9a55 100644 --- a/src/scpi.h +++ b/src/scpi.h @@ -163,4 +163,10 @@ SR_PRIV int sr_scpi_cmd_resp(const struct sr_dev_inst *sdi, int channel_command, const char *channel_name, GVariant **gvar, const GVariantType *gvtype, int command, ...); +/*--- GPIB only functions ---------------------------------------------------*/ + +#ifdef HAVE_LIBGPIB +SR_PRIV int sr_scpi_gpib_spoll(struct sr_scpi_dev_inst *scpi, char *buf); +#endif + #endif diff --git a/src/scpi/scpi_libgpib.c b/src/scpi/scpi_libgpib.c index 2f3256be..8f200e7d 100644 --- a/src/scpi/scpi_libgpib.c +++ b/src/scpi/scpi_libgpib.c @@ -155,6 +155,22 @@ 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; + + ibrsp(gscpi->descriptor, buf); + + if (ibsta & ERR) { + sr_err("Error while serial polling: iberr = %s.", + gpib_error_string(iberr)); + return SR_ERR; + } + 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",