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.
This commit is contained in:
Frank Stettner 2019-02-01 12:18:46 +01:00 committed by Uwe Hermann
parent 1b6b9c01df
commit 02d4db3562
3 changed files with 40 additions and 7 deletions

View File

@ -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);

View File

@ -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

View File

@ -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",