X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fscpi-pps%2Fapi.c;h=98ef0b9d7b01932fb902e77bdd21d13a9704c882;hb=f083ae63c7355b9b1d99775785b99b6fa91cd48a;hp=a35052dfebbb71215058ab2810b3640d7c768053;hpb=17a82e83ff4c2a7dc1bcc4f5ab6197c16a3b72de;p=libsigrok.git diff --git a/src/hardware/scpi-pps/api.c b/src/hardware/scpi-pps/api.c index a35052df..98ef0b9d 100644 --- a/src/hardware/scpi-pps/api.c +++ b/src/hardware/scpi-pps/api.c @@ -2,6 +2,7 @@ * This file is part of the libsigrok project. * * Copyright (C) 2014 Bert Vermeulen + * Copyright (C) 2017,2019 Frank Stettner * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -99,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) { @@ -150,6 +152,13 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi, for (l = sdi->channels; l; l = l->next) { ch = l->data; pch = ch->priv; + /* Add mqflags from channel_group_spec only to voltage + * and current channels + */ + if (pch->mq == SR_MQ_VOLTAGE || pch->mq == SR_MQ_CURRENT) + pch->mqflags = cgs->mqflags; + else + pch->mqflags = 0; if (pch->hw_output_idx == j) cg->channels = g_slist_append(cg->channels, ch); } @@ -311,6 +320,7 @@ static int config_get(uint32_t key, GVariant **data, char *channel_group_name; int cmd, ret; const char *s; + int reg; if (!sdi) return SR_ERR_ARG; @@ -373,7 +383,11 @@ static int config_get(uint32_t key, GVariant **data, cmd = SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ENABLED; break; case SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE: - gvtype = G_VARIANT_TYPE_BOOLEAN; + if (devc->device->dialect == SCPI_DIALECT_HP_66XXB || + devc->device->dialect == SCPI_DIALECT_HP_COMP) + gvtype = G_VARIANT_TYPE_STRING; + else + gvtype = G_VARIANT_TYPE_BOOLEAN; cmd = SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE; break; case SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD: @@ -385,7 +399,11 @@ static int config_get(uint32_t key, GVariant **data, cmd = SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED; break; case SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE: - gvtype = G_VARIANT_TYPE_BOOLEAN; + if (devc->device->dialect == SCPI_DIALECT_HP_66XXB || + devc->device->dialect == SCPI_DIALECT_HP_COMP) + gvtype = G_VARIANT_TYPE_STRING; + else + gvtype = G_VARIANT_TYPE_BOOLEAN; cmd = SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE; break; case SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD: @@ -396,9 +414,20 @@ static int config_get(uint32_t key, GVariant **data, gvtype = G_VARIANT_TYPE_BOOLEAN; cmd = SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION; break; + case SR_CONF_OVER_TEMPERATURE_PROTECTION_ACTIVE: + if (devc->device->dialect == SCPI_DIALECT_HP_66XXB || + devc->device->dialect == SCPI_DIALECT_HP_COMP) + gvtype = G_VARIANT_TYPE_STRING; + else + gvtype = G_VARIANT_TYPE_BOOLEAN; + cmd = SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION_ACTIVE; + break; 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; @@ -414,28 +443,116 @@ 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_COMP) { + /* Evaluate Status Register from a HP 66xx in COMP mode. */ + s = g_variant_get_string(*data, NULL); + sr_atoi(s, ®); g_variant_unref(*data); - *data = g_variant_new_string("CV"); - } else if (!strcmp(s, "CURR")) { + if (reg & (1 << 0)) + *data = g_variant_new_string("CV"); + else if (reg & (1 << 1)) + *data = g_variant_new_string("CC"); + else if (reg & (1 << 2)) + *data = g_variant_new_string("UR"); + else if (reg & (1 << 9)) + *data = g_variant_new_string("CC-"); + else + *data = g_variant_new_string(""); + } + 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, ®); g_variant_unref(*data); - *data = g_variant_new_string("CC"); + if (reg & (1 << 8)) + *data = g_variant_new_string("CV"); + else if (reg & (1 << 10)) + *data = g_variant_new_string("CC"); + else if (reg & (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") && g_strcmp0(s, "")) { + + sr_err("Unknown response to SCPI_CMD_GET_OUTPUT_REGULATION: %s", s); ret = SR_ERR_DATA; } } + if (cmd == SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE) { + if (devc->device->dialect == SCPI_DIALECT_HP_COMP) { + /* Evaluate Status Register from a HP 66xx in COMP mode. */ + s = g_variant_get_string(*data, NULL); + sr_atoi(s, ®); + g_variant_unref(*data); + *data = g_variant_new_boolean(reg & (1 << 3)); + } + if (devc->device->dialect == SCPI_DIALECT_HP_66XXB) { + /* Evaluate Questionable Status Register bit 0 from a HP 66xxB. */ + s = g_variant_get_string(*data, NULL); + sr_atoi(s, ®); + g_variant_unref(*data); + *data = g_variant_new_boolean(reg & (1 << 0)); + } + } + + if (cmd == SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE) { + if (devc->device->dialect == SCPI_DIALECT_HP_COMP) { + /* Evaluate Status Register from a HP 66xx in COMP mode. */ + s = g_variant_get_string(*data, NULL); + sr_atoi(s, ®); + g_variant_unref(*data); + *data = g_variant_new_boolean(reg & (1 << 6)); + } + if (devc->device->dialect == SCPI_DIALECT_HP_66XXB) { + /* Evaluate Questionable Status Register bit 1 from a HP 66xxB. */ + s = g_variant_get_string(*data, NULL); + sr_atoi(s, ®); + g_variant_unref(*data); + *data = g_variant_new_boolean(reg & (1 << 1)); + } + } + + if (cmd == SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION_ACTIVE) { + if (devc->device->dialect == SCPI_DIALECT_HP_COMP) { + /* Evaluate Status Register from a HP 66xx in COMP mode. */ + s = g_variant_get_string(*data, NULL); + sr_atoi(s, ®); + g_variant_unref(*data); + *data = g_variant_new_boolean(reg & (1 << 4)); + } + if (devc->device->dialect == SCPI_DIALECT_HP_66XXB) { + /* Evaluate Questionable Status Register bit 4 from a HP 66xxB. */ + s = g_variant_get_string(*data, NULL); + sr_atoi(s, ®); + g_variant_unref(*data); + *data = g_variant_new_boolean(reg & (1 << 4)); + } + } + return ret; } @@ -532,7 +649,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); @@ -609,6 +726,12 @@ static int config_list(uint32_t key, GVariant **data, case SR_CONF_CURRENT_LIMIT: *data = std_gvar_min_max_step_array(ch_spec->current); break; + case SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD: + *data = std_gvar_min_max_step_array(ch_spec->ovp); + break; + case SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD: + *data = std_gvar_min_max_step_array(ch_spec->ocp); + break; default: return SR_ERR_NA; } @@ -629,10 +752,15 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi) /* Prime the pipe with the first channel. */ devc->cur_acquisition_channel = sr_next_enabled_channel(sdi, NULL); + /* Device specific initialization before aquisition starts. */ + if (devc->device->init_aquisition) + devc->device->init_aquisition(sdi); + if ((ret = sr_scpi_source_add(sdi->session, scpi, G_IO_IN, 10, 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; } @@ -640,18 +768,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);