]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/scpi-dmm/api.c
rigol-dg: Add device/firmware specific quirks support.
[libsigrok.git] / src / hardware / scpi-dmm / api.c
index 69f6fa2aef33debbaabddc3ed6d9dc6954b0c876..7867ebc2acd48b336e47a6efd9c591a7ec607550 100644 (file)
@@ -33,6 +33,7 @@ static const uint32_t drvopts[] = {
 
 static const uint32_t devopts_generic[] = {
        SR_CONF_CONTINUOUS,
+       SR_CONF_CONN | SR_CONF_GET,
        SR_CONF_LIMIT_SAMPLES | SR_CONF_GET | SR_CONF_SET,
        SR_CONF_LIMIT_MSEC | SR_CONF_GET | SR_CONF_SET,
        SR_CONF_MEASURED_QUANTITY | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
@@ -82,10 +83,10 @@ static const struct scpi_command cmdset_hp[] = {
 
 static const struct scpi_command cmdset_gwinstek[] = {
        { DMM_CMD_SETUP_REMOTE, "SYST:REM", },
+       { DMM_CMD_SETUP_LOCAL, "SYST:LOC", },
        { DMM_CMD_SETUP_FUNC, "CONF:%s", },
        { DMM_CMD_QUERY_FUNC, "CONF:STAT:FUNC?", },
        { DMM_CMD_START_ACQ, "*CLS;SYST:REM", },
-       { DMM_CMD_STOP_ACQ, "SYST:LOC", },
        { DMM_CMD_QUERY_VALUE, "VAL1?", },
        { DMM_CMD_QUERY_PREC, "SENS:DET:RATE?", },
        ALL_ZERO,
@@ -93,10 +94,11 @@ static const struct scpi_command cmdset_gwinstek[] = {
 
 static const struct scpi_command cmdset_gwinstek_906x[] = {
        { DMM_CMD_SETUP_REMOTE, "SYST:REM", },
+       { DMM_CMD_SETUP_LOCAL, "SYST:LOC", },
        { DMM_CMD_SETUP_FUNC, "CONF:%s", },
        { DMM_CMD_QUERY_FUNC, "CONF?", },
-       { DMM_CMD_START_ACQ, "*CLS;SYST:REM", },
-       { DMM_CMD_STOP_ACQ, "SYST:LOC", },
+       { DMM_CMD_START_ACQ, "INIT", },
+       { DMM_CMD_STOP_ACQ, "ABORT", },
        { DMM_CMD_QUERY_VALUE, "VAL1?", },
        { DMM_CMD_QUERY_PREC, "SENS:DET:RATE?", },
        ALL_ZERO,
@@ -249,6 +251,7 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
        struct dev_context *devc;
        size_t i;
        gchar *channel_name;
+       const char *command;
 
        scpi_dmm_cmd_delay(scpi);
        ret = sr_scpi_get_hw_id(scpi, &hw_info);
@@ -271,6 +274,11 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
        sdi->conn = scpi;
        sdi->driver = &scpi_dmm_driver_info;
        sdi->inst_type = SR_INST_SCPI;
+       ret = sr_scpi_connection_id(scpi, &sdi->connection_id);
+       if (ret != SR_OK) {
+               g_free(sdi->connection_id);
+               sdi->connection_id = NULL;
+       }
        sr_scpi_hw_info_free(hw_info);
        if (model->read_timeout_us)  /* non-default read timeout */
                scpi->read_timeout_us = model->read_timeout_us;
@@ -285,6 +293,16 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
                sr_channel_new(sdi, 0, SR_CHANNEL_ANALOG, TRUE, channel_name);
        }
 
+       /*
+        * If device has DMM_CMD_SETUP_LOCAL command, send it now. To avoid
+        * leaving device in remote mode (if only a "scan" is run).
+        */
+       command = sr_scpi_cmd_get(devc->cmdset, DMM_CMD_SETUP_LOCAL);
+       if (command && *command) {
+               scpi_dmm_cmd_delay(scpi);
+               sr_scpi_send(scpi, command);
+       }
+
        return sdi;
 }
 
@@ -310,8 +328,11 @@ static int dev_open(struct sr_dev_inst *sdi)
 
 static int dev_close(struct sr_dev_inst *sdi)
 {
+       struct dev_context *devc;
        struct sr_scpi_dev_inst *scpi;
+       const char *command;
 
+       devc = sdi->priv;
        scpi = sdi->conn;
        if (!scpi)
                return SR_ERR_BUG;
@@ -320,6 +341,16 @@ static int dev_close(struct sr_dev_inst *sdi)
        if (sdi->status <= SR_ST_INACTIVE)
                return SR_OK;
 
+       /*
+        * If device has DMM_CMD_SETUP_LOCAL command, send it now
+        * to avoid leaving device in remote mode.
+        */
+       command = sr_scpi_cmd_get(devc->cmdset, DMM_CMD_SETUP_LOCAL);
+       if (command && *command) {
+               scpi_dmm_cmd_delay(scpi);
+               sr_scpi_send(scpi, command);
+       }
+
        return sr_scpi_close(scpi);
 }
 
@@ -337,6 +368,11 @@ static int config_get(uint32_t key, GVariant **data,
        devc = sdi->priv;
 
        switch (key) {
+       case SR_CONF_CONN:
+               if (!sdi || !sdi->connection_id)
+                       return SR_ERR_NA;
+               *data = g_variant_new_string(sdi->connection_id);
+               return SR_OK;
        case SR_CONF_LIMIT_SAMPLES:
        case SR_CONF_LIMIT_MSEC:
                return sr_sw_limits_config_get(&devc->limits, key, data);