]> sigrok.org Git - libsigrok.git/commitdiff
korad-kaxxxxp: Fix bug when setting values while acquisition is running.
authorFrank Stettner <redacted>
Tue, 9 Apr 2019 12:20:41 +0000 (14:20 +0200)
committerUwe Hermann <redacted>
Mon, 16 Dec 2019 14:42:36 +0000 (15:42 +0100)
By separating the variables that holds the get and set values, the output
state, OVP and OCP can now be set while the acquisition is running.
Also some variables are named more clearly.

src/hardware/korad-kaxxxxp/api.c
src/hardware/korad-kaxxxxp/protocol.c
src/hardware/korad-kaxxxxp/protocol.h

index d2c6cdcfa52b3fa1182ad07e683ac8ed237910b3..268de9f6b934e25ed6eec5e90a738170f588c8ec 100644 (file)
@@ -199,16 +199,16 @@ static int config_get(uint32_t key, GVariant **data,
                *data = g_variant_new_double(devc->voltage);
                break;
        case SR_CONF_VOLTAGE_TARGET:
-               korad_kaxxxxp_get_value(sdi->conn, KAXXXXP_VOLTAGE_MAX, devc);
-               *data = g_variant_new_double(devc->voltage_max);
+               korad_kaxxxxp_get_value(sdi->conn, KAXXXXP_VOLTAGE_TARGET, devc);
+               *data = g_variant_new_double(devc->voltage_target);
                break;
        case SR_CONF_CURRENT:
                korad_kaxxxxp_get_value(sdi->conn, KAXXXXP_CURRENT, devc);
                *data = g_variant_new_double(devc->current);
                break;
        case SR_CONF_CURRENT_LIMIT:
-               korad_kaxxxxp_get_value(sdi->conn, KAXXXXP_CURRENT_MAX, devc);
-               *data = g_variant_new_double(devc->current_max);
+               korad_kaxxxxp_get_value(sdi->conn, KAXXXXP_CURRENT_LIMIT, devc);
+               *data = g_variant_new_double(devc->current_limit);
                break;
        case SR_CONF_ENABLED:
                korad_kaxxxxp_get_value(sdi->conn, KAXXXXP_OUTPUT, devc);
@@ -253,34 +253,34 @@ static int config_set(uint32_t key, GVariant *data,
                dval = g_variant_get_double(data);
                if (dval < devc->model->voltage[0] || dval > devc->model->voltage[1])
                        return SR_ERR_ARG;
-               devc->voltage_max = dval;
-               if (korad_kaxxxxp_set_value(sdi->conn, KAXXXXP_VOLTAGE_MAX, devc) < 0)
+               devc->set_voltage_target = dval;
+               if (korad_kaxxxxp_set_value(sdi->conn, KAXXXXP_VOLTAGE_TARGET, devc) < 0)
                        return SR_ERR;
                break;
        case SR_CONF_CURRENT_LIMIT:
                dval = g_variant_get_double(data);
                if (dval < devc->model->current[0] || dval > devc->model->current[1])
                        return SR_ERR_ARG;
-               devc->current_max = dval;
-               if (korad_kaxxxxp_set_value(sdi->conn, KAXXXXP_CURRENT_MAX, devc) < 0)
+               devc->set_current_limit = dval;
+               if (korad_kaxxxxp_set_value(sdi->conn, KAXXXXP_CURRENT_LIMIT, devc) < 0)
                        return SR_ERR;
                break;
        case SR_CONF_ENABLED:
                bval = g_variant_get_boolean(data);
                /* Set always so it is possible turn off with sigrok-cli. */
-               devc->output_enabled = bval;
+               devc->set_output_enabled = bval;
                if (korad_kaxxxxp_set_value(sdi->conn, KAXXXXP_OUTPUT, devc) < 0)
                        return SR_ERR;
                break;
        case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED:
                bval = g_variant_get_boolean(data);
-               devc->ocp_enabled = bval;
+               devc->set_ocp_enabled = bval;
                if (korad_kaxxxxp_set_value(sdi->conn, KAXXXXP_OCP, devc) < 0)
                        return SR_ERR;
                break;
        case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED:
                bval = g_variant_get_boolean(data);
-               devc->ovp_enabled = bval;
+               devc->set_ovp_enabled = bval;
                if (korad_kaxxxxp_set_value(sdi->conn, KAXXXXP_OVP, devc) < 0)
                        return SR_ERR;
                break;
index e9345a75983ae2fe1f660f92ae28985a87a0f29a..bcda463379f4d2030ba9a9e5c05f68ab2c77da45 100644 (file)
@@ -96,29 +96,35 @@ SR_PRIV int korad_kaxxxxp_set_value(struct sr_serial_dev_inst *serial,
                sr_err("Can't set measurable parameter %d.", target);
                g_mutex_unlock(&devc->rw_mutex);
                return SR_ERR;
-       case KAXXXXP_CURRENT_MAX:
+       case KAXXXXP_CURRENT_LIMIT:
                cmd = "ISET1:%05.3f";
-               value = devc->current_max;
+               value = devc->set_current_limit;
                break;
-       case KAXXXXP_VOLTAGE_MAX:
+       case KAXXXXP_VOLTAGE_TARGET:
                cmd = "VSET1:%05.2f";
-               value = devc->voltage_max;
+               value = devc->set_voltage_target;
                break;
        case KAXXXXP_OUTPUT:
                cmd = "OUT%01.0f";
-               value = (devc->output_enabled) ? 1 : 0;
+               value = (devc->set_output_enabled) ? 1 : 0;
+               /* Set value back to recognize changes */
+               devc->output_enabled = devc->set_output_enabled;
                break;
        case KAXXXXP_BEEP:
                cmd = "BEEP%01.0f";
-               value = (devc->beep_enabled) ? 1 : 0;
+               value = (devc->set_beep_enabled) ? 1 : 0;
                break;
        case KAXXXXP_OCP:
                cmd = "OCP%01.0f";
-               value = (devc->ocp_enabled) ? 1 : 0;
+               value = (devc->set_ocp_enabled) ? 1 : 0;
+               /* Set value back to recognize changes */
+               devc->ocp_enabled = devc->set_ocp_enabled;
                break;
        case KAXXXXP_OVP:
                cmd = "OVP%01.0f";
-               value = (devc->ovp_enabled) ? 1 : 0;
+               value = (devc->set_ovp_enabled) ? 1 : 0;
+               /* Set value back to recognize changes */
+               devc->ovp_enabled = devc->set_ovp_enabled;
                break;
        case KAXXXXP_SAVE:
                cmd = "SAV%01.0f";
@@ -179,20 +185,20 @@ SR_PRIV int korad_kaxxxxp_get_value(struct sr_serial_dev_inst *serial,
                ret = korad_kaxxxxp_send_cmd(serial, "IOUT1?");
                value = &(devc->current);
                break;
-       case KAXXXXP_CURRENT_MAX:
+       case KAXXXXP_CURRENT_LIMIT:
                /* Read set current from device. */
                ret = korad_kaxxxxp_send_cmd(serial, "ISET1?");
-               value = &(devc->current_max);
+               value = &(devc->current_limit);
                break;
        case KAXXXXP_VOLTAGE:
                /* Read voltage from device. */
                ret = korad_kaxxxxp_send_cmd(serial, "VOUT1?");
                value = &(devc->voltage);
                break;
-       case KAXXXXP_VOLTAGE_MAX:
+       case KAXXXXP_VOLTAGE_TARGET:
                /* Read set voltage from device. */
                ret = korad_kaxxxxp_send_cmd(serial, "VSET1?");
-               value = &(devc->voltage_max);
+               value = &(devc->voltage_target);
                break;
        case KAXXXXP_STATUS:
        case KAXXXXP_OUTPUT:
@@ -241,7 +247,7 @@ SR_PRIV int korad_kaxxxxp_get_value(struct sr_serial_dev_inst *serial,
                sr_spew("Status: CH1: constant %s CH2: constant %s. "
                        "Tracking would be %s. Device is "
                        "%s and %s. Buttons are %s. Output is %s "
-                       "and extra byte is %s.",
+                       "and extra bit is %s.",
                        (status_byte & (1 << 0)) ? "voltage" : "current",
                        (status_byte & (1 << 1)) ? "voltage" : "current",
                        (status_byte & (1 << 2)) ? "parallel" : "series",
@@ -253,7 +259,7 @@ SR_PRIV int korad_kaxxxxp_get_value(struct sr_serial_dev_inst *serial,
        }
 
        /* Read the sixth byte from ISET? BUG workaround. */
-       if (target == KAXXXXP_CURRENT_MAX)
+       if (target == KAXXXXP_CURRENT_LIMIT)
                serial_read_blocking(serial, &status_byte, 1, 10);
 
        g_mutex_unlock(&devc->rw_mutex);
index 6b4c3c2207cf7787c2996a6f41c5382fc77bfcf0..f2f135707f156fa6088b1fd7ee34267d20866073 100644 (file)
@@ -62,9 +62,9 @@ struct korad_kaxxxxp_model {
 /* Reply targets */
 enum {
        KAXXXXP_CURRENT,
-       KAXXXXP_CURRENT_MAX,
+       KAXXXXP_CURRENT_LIMIT,
        KAXXXXP_VOLTAGE,
-       KAXXXXP_VOLTAGE_MAX,
+       KAXXXXP_VOLTAGE_TARGET,
        KAXXXXP_STATUS,
        KAXXXXP_OUTPUT,
        KAXXXXP_BEEP,
@@ -82,9 +82,9 @@ struct dev_context {
        GMutex rw_mutex;
 
        float current;          /**< Last current value [A] read from device. */
-       float current_max;      /**< Output current set. */
+       float current_limit;    /**< Output current set. */
        float voltage;          /**< Last voltage value [V] read from device. */
-       float voltage_max;      /**< Output voltage set. */
+       float voltage_target;   /**< Output voltage set. */
        gboolean cc_mode[2];    /**< Device is in CC mode (otherwise CV). */
 
        gboolean output_enabled; /**< Is the output enabled? */
@@ -94,6 +94,13 @@ struct dev_context {
 
        int acquisition_target;  /**< What reply to expect. */
        int program;             /**< Program to store or recall. */
+
+       float set_current_limit;     /**< New output current to set. */
+       float set_voltage_target;    /**< New output voltage to set. */
+       gboolean set_output_enabled; /**< New output enabled to set. */
+       gboolean set_beep_enabled;   /**< New enable beeper to set. */
+       gboolean set_ocp_enabled;    /**< New OCP enabled to set. */
+       gboolean set_ovp_enabled;    /**< New OVP enabled to set. */
 };
 
 SR_PRIV int korad_kaxxxxp_send_cmd(struct sr_serial_dev_inst *serial,