struct sr_scpi_dev_inst *scpi;
struct sr_dev_inst *sdi;
struct dev_context *devc;
+ char status_register;
(void)fd;
(void)revents;
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);
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
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",