]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/scpi-dmm/api.c
scpi-dmm: Gracefully handle meters that lack OPC command.
[libsigrok.git] / src / hardware / scpi-dmm / api.c
index 456c24dbf9ea93e13668efa56b482f642057185a..c6753860b866a072443e9221acd04179bd48ebe9 100644 (file)
@@ -241,6 +241,25 @@ static const struct scpi_dmm_model *is_compatible(const char *vendor, const char
        return NULL;
 }
 
+/*
+ * Some devices (such as Owon XDM2041) do not support the standard
+ * OPeration Complete? command. This function tests the command with
+ * a short timeout, and returns TRUE if any reply (busy or not) is received.
+ */
+static gboolean probe_opc_support(struct sr_scpi_dev_inst *scpi)
+{
+       gboolean result;
+       GString *response;
+
+       response = g_string_sized_new(128);
+       result = TRUE;
+       if (sr_scpi_get_data(scpi, SCPI_CMD_OPC, &response) != SR_OK)
+               result = FALSE;
+       g_string_free(response, TRUE);
+
+       return result;
+}
+
 static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
 {
        struct sr_scpi_hw_info *hw_info;
@@ -253,6 +272,9 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
        gchar *channel_name;
        const char *command;
 
+       if (!probe_opc_support(scpi))
+               scpi->no_opc_command = TRUE;
+
        scpi_dmm_cmd_delay(scpi);
        ret = sr_scpi_get_hw_id(scpi, &hw_info);
        if (ret != SR_OK) {