]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/scpi-pps/api.c
scpi-pps: Add SR_CONF_REGULATION for HP 66xxB power supplies.
[libsigrok.git] / src / hardware / scpi-pps / api.c
index c0b32e13e45faee84c355995a907c295bff90e99..22c79740ed1fada6f042e2b644ebe6b16dd40e86 100644 (file)
@@ -100,6 +100,7 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi,
 
        devc = g_malloc0(sizeof(struct dev_context));
        devc->device = device;
+       sr_sw_limits_init(&devc->limits);
        sdi->priv = devc;
 
        if (device->num_channels) {
@@ -312,6 +313,7 @@ static int config_get(uint32_t key, GVariant **data,
        char *channel_group_name;
        int cmd, ret;
        const char *s;
+       int oper_cond;
 
        if (!sdi)
                return SR_ERR_ARG;
@@ -400,6 +402,9 @@ static int config_get(uint32_t key, GVariant **data,
        case SR_CONF_REGULATION:
                gvtype = G_VARIANT_TYPE_STRING;
                cmd = SCPI_CMD_GET_OUTPUT_REGULATION;
+               break;
+       default:
+               return sr_sw_limits_config_get(&devc->limits, key, data);
        }
        if (!gvtype)
                return SR_ERR_NA;
@@ -415,24 +420,45 @@ static int config_get(uint32_t key, GVariant **data,
                channel_group_cmd, channel_group_name, data, gvtype, cmd);
        g_free(channel_group_name);
 
+       /*
+        * Handle special cases
+        */
+
        if (cmd == SCPI_CMD_GET_OUTPUT_REGULATION) {
-               /*
-                * The Rigol DP800 series return CV/CC/UR, Philips PM2800
-                * return VOLT/CURR. We always return a GVariant string in
-                * the Rigol notation.
-                */
-               s = g_variant_get_string(*data, NULL);
-               if (!strcmp(s, "VOLT")) {
-                       g_variant_unref(*data);
-                       *data = g_variant_new_string("CV");
-               } else if (!strcmp(s, "CURR")) {
+               if (devc->device->dialect == SCPI_DIALECT_PHILIPS) {
+                       /*
+                       * The Philips PM2800 series returns VOLT/CURR. We always return
+                       * a GVariant string in the Rigol notation (CV/CC/UR).
+                       */
+                       s = g_variant_get_string(*data, NULL);
+                       if (!g_strcmp0(s, "VOLT")) {
+                               g_variant_unref(*data);
+                               *data = g_variant_new_string("CV");
+                       } else if (!g_strcmp0(s, "CURR")) {
+                               g_variant_unref(*data);
+                               *data = g_variant_new_string("CC");
+                       }
+               }
+               if (devc->device->dialect == SCPI_DIALECT_HP_66XXB) {
+                       /* Evaluate Operational Status Register from a HP 66xxB. */
+                       s = g_variant_get_string(*data, NULL);
+                       sr_atoi(s, &oper_cond);
                        g_variant_unref(*data);
-                       *data = g_variant_new_string("CC");
+                       if (oper_cond & (1 << 8))
+                               *data = g_variant_new_string("CV");
+                       else if (oper_cond & (1 << 10))
+                               *data = g_variant_new_string("CC");
+                       else if (oper_cond & (1 << 11))
+                               *data = g_variant_new_string("CC-");
+                       else
+                               *data = g_variant_new_string("UR");
                }
 
                s = g_variant_get_string(*data, NULL);
-               if (strcmp(s, "CV") && strcmp(s, "CC") && strcmp(s, "UR")) {
-                       sr_dbg("Unknown response to SCPI_CMD_GET_OUTPUT_REGULATION: %s", s);
+               if (g_strcmp0(s, "CV") && g_strcmp0(s, "CC") &&
+                       g_strcmp0(s, "CC-") && g_strcmp0(s, "UR")) {
+
+                       sr_err("Unknown response to SCPI_CMD_GET_OUTPUT_REGULATION: %s", s);
                        ret = SR_ERR_DATA;
                }
        }
@@ -533,7 +559,7 @@ static int config_set(uint32_t key, GVariant *data,
                                        SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_DISABLE);
                break;
        default:
-               ret = SR_ERR_NA;
+               ret = sr_sw_limits_config_set(&devc->limits, key, data);
        }
 
        g_free(channel_group_name);
@@ -640,6 +666,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
                        scpi_pps_receive_data, (void *)sdi)) != SR_OK)
                return ret;
        std_session_send_df_header(sdi);
+       sr_sw_limits_acquisition_start(&devc->limits);
 
        return SR_OK;
 }
@@ -647,18 +674,9 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
 static int dev_acquisition_stop(struct sr_dev_inst *sdi)
 {
        struct sr_scpi_dev_inst *scpi;
-       double d;
 
        scpi = sdi->conn;
 
-       /*
-        * A requested value is certainly on the way. Retrieve it now,
-        * to avoid leaving the device in a state where it's not expecting
-        * commands.
-        *
-        * TODO: Doesn't work for (at least) the HP 66XXB models.
-        */
-       sr_scpi_get_double(scpi, NULL, &d);
        sr_scpi_source_remove(sdi->session, scpi);
 
        std_session_send_df_end(sdi);