diff --git a/include/libsigrok/libsigrok.h b/include/libsigrok/libsigrok.h index 508ea3bd..bb0b4fe7 100644 --- a/include/libsigrok/libsigrok.h +++ b/include/libsigrok/libsigrok.h @@ -956,6 +956,8 @@ enum sr_configkey { * Channel regulation * get: "CV", "CC" or "UR", denoting constant voltage, constant current * or unregulated. + * "CC-" denotes a power supply in current sink mode (e.g. HP 66xxB). + * "" is used when there is no regulation, e.g. the output is disabled. */ SR_CONF_REGULATION, diff --git a/src/hardware/scpi-pps/api.c b/src/hardware/scpi-pps/api.c index d1dab458..22c79740 100644 --- a/src/hardware/scpi-pps/api.c +++ b/src/hardware/scpi-pps/api.c @@ -313,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; @@ -419,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")) { + 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("CV"); - } else if (!strcmp(s, "CURR")) { - 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; } } diff --git a/src/hardware/scpi-pps/profiles.c b/src/hardware/scpi-pps/profiles.c index c9ddd61e..6d52b05b 100644 --- a/src/hardware/scpi-pps/profiles.c +++ b/src/hardware/scpi-pps/profiles.c @@ -460,6 +460,7 @@ static const uint32_t hp_6630b_devopts_cg[] = { SR_CONF_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, SR_CONF_OVER_CURRENT_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET, + SR_CONF_REGULATION | SR_CONF_GET, }; static const struct channel_spec hp_6633a_ch[] = { @@ -520,6 +521,7 @@ static const struct scpi_command hp_6630b_cmd[] = { { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE, ":CURR:PROT:STAT 0" }, { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":VOLT:PROT?" }, { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":VOLT:PROT %.6f" }, + { SCPI_CMD_GET_OUTPUT_REGULATION, "STAT:OPER:COND?" }, ALL_ZERO };