]> sigrok.org Git - libsigrok.git/commitdiff
Support for regulation status and fix for mysterious M
authorHannu Vuolasaho <redacted>
Wed, 21 Oct 2015 16:04:37 +0000 (19:04 +0300)
committerUwe Hermann <redacted>
Thu, 29 Oct 2015 17:43:09 +0000 (18:43 +0100)
Added support for SR_CONF_REGULATION which returns value for CH1
Also VELLEMAN LABPS3005D (only device currently supported) sends single
'M' character in beginning of return value, which is specially discarded.

src/hardware/korad-kdxxxxp/api.c
src/hardware/korad-kdxxxxp/protocol.c

index 107bdc4070d258cc1cf8f986e0f01ca72f94586b..4a6c8179ca4924d49fdedfdccbba6e1cc109c3a4 100644 (file)
@@ -43,6 +43,7 @@ static const uint32_t devopts[] = {
        SR_CONF_CURRENT | SR_CONF_GET,
        SR_CONF_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
        SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET,
+       SR_CONF_REGULATION | SR_CONF_GET,
 };
 
 static const struct korad_kdxxxxp_model models[] = {
@@ -217,6 +218,13 @@ static int config_get(uint32_t key, GVariant **data,
        case SR_CONF_ENABLED:
                *data = g_variant_new_boolean(devc->output_enabled);
                break;
+       case SR_CONF_REGULATION:
+               /* Dual channel not supported. */
+               if (devc->cc_mode[0])
+                       *data = g_variant_new_string("CC");
+               else
+                       *data = g_variant_new_string("CV");
+               break;
        default:
                return SR_ERR_NA;
        }
index cd266e2fc718e6c5c02a0882530fb43ed9b1a187..eb5281037b7d6c939a7e39b143007074ad5fc926 100644 (file)
@@ -202,7 +202,7 @@ SR_PRIV int korad_kdxxxxp_get_reply(struct sr_serial_dev_inst *serial,
                                struct dev_context *devc)
 {
        double value;
-       int count, ret;
+       int count, ret, i;
        float *target;
        char status_byte;
 
@@ -241,6 +241,16 @@ SR_PRIV int korad_kdxxxxp_get_reply(struct sr_serial_dev_inst *serial,
        devc->reply[count] = 0;
 
        if (target) {
+               /* Handle the strange 'M' */
+               if (devc->reply[0] == 'M') {
+                       for (i = 1; i < count; ++i) {
+                               devc->reply[i - 1] = devc->reply[i];
+                       }
+                       /* Get the last character */
+                       if (( i = korad_kdxxxxp_read_chars(serial, 1,
+                                               &(devc->reply[count]))) < 0)
+                               return i;
+               }
                value = g_ascii_strtod(devc->reply, NULL);
                *target = (float)value;
                sr_dbg("value: %f",value);