]> sigrok.org Git - libsigrok.git/commitdiff
scpi: Add a function to read and wait on a *OPC? reply.
authorpoljar (Damir Jelić) <redacted>
Sat, 9 Nov 2013 11:49:08 +0000 (12:49 +0100)
committerUwe Hermann <redacted>
Tue, 3 Dec 2013 14:10:01 +0000 (15:10 +0100)
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.

hardware/common/scpi.c
libsigrok-internal.h

index 03eea3eea747a6b1c16a7c99c4e6b923b6e1399e..b29e14ba61336514c0b40cbbe5daeeed1c9a7a8f 100644 (file)
@@ -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.
index fa270b4e477e3bd158394b4ff1032cfbb5a1e424..b8a3fde505dbf3cedeb9e8e7d4276644482d6798 100644 (file)
@@ -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);