From: poljar (Damir Jelić) Date: Sat, 9 Nov 2013 11:49:08 +0000 (+0100) Subject: scpi: Add a function to read and wait on a *OPC? reply. X-Git-Tag: libsigrok-0.3.0~511 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=f5922adef5a866bd1c292436f1c4bc6b93103aef;p=libsigrok.git scpi: Add a function to read and wait on a *OPC? reply. The SCPI standard specifies the "*OPC?" command (Operation complete query) which queries the instrument for its operative state. When all pending operations are complete, the instrument responds with a "1". Some manufacturers block before completing all operations and don't respond with anything and some of them respond with a "0". This function handles both cases uniformly. --- diff --git a/hardware/common/scpi.c b/hardware/common/scpi.c index 03eea3ee..b29e14ba 100644 --- a/hardware/common/scpi.c +++ b/hardware/common/scpi.c @@ -307,6 +307,31 @@ SR_PRIV int sr_scpi_get_double(struct sr_serial_dev_inst *serial, return ret; } +/** + * Send a SCPI *OPC? command, read the reply and return the result of the + * command. + * + * @param serial Previously initialized serial port structure. + * + * @return SR_OK on success, SR_ERR on failure. + */ +SR_PRIV int sr_scpi_get_opc(struct sr_serial_dev_inst *serial) +{ + unsigned int i; + gboolean opc; + + for (i = 0; i < SCPI_READ_RETRIES; ++i) { + sr_scpi_get_bool(serial, SCPI_CMD_OPC, &opc); + + if (opc) + return SR_OK; + + g_usleep(SCPI_READ_RETRY_TIMEOUT); + } + + return SR_ERR; +} + /** * Send the *IDN? SCPI command, receive the reply, parse it and store the * reply as a sr_scpi_hw_info structure in the supplied scpi_response pointer. diff --git a/libsigrok-internal.h b/libsigrok-internal.h index fa270b4e..b8a3fde5 100644 --- a/libsigrok-internal.h +++ b/libsigrok-internal.h @@ -288,6 +288,7 @@ SR_PRIV int sr_scpi_get_float(struct sr_serial_dev_inst *serial, const char *command, float *scpi_response); SR_PRIV int sr_scpi_get_double(struct sr_serial_dev_inst *serial, const char *command, double *scpi_response); +SR_PRIV int sr_scpi_get_opc(struct sr_serial_dev_inst *serial); SR_PRIV int sr_scpi_get_hw_id(struct sr_serial_dev_inst *serial, struct sr_scpi_hw_info **scpi_reponse); SR_PRIV void sr_scpi_hw_info_free(struct sr_scpi_hw_info *hw_info);