2015-10-19 16:37 GMT+03:00 Uwe Hermann <u...@hermann-uwe.de>: > Hi, > > On Fri, Sep 25, 2015 at 06:01:30PM +0300, Hannu Vuolasaho wrote: >> I bough Velleman power supply and now I've written driver for it. > > Merged after some discussions on IRC and a few changes as 'korad-kdxxxxp' > (Velleman devices are rebranded Korad devices), thanks a lot! The driver name > might need another rename possibly to properly catch all supportable devices.
Hopefully people buy rebranded Korad stuff, so this driver support can be expanded. Actually real korad would be nice too. I believe I have written all usable commands, which I can test. If someone has Korad kd3305p which has two adjustable channels and third constant 5 volts, adding first channel support would be easy and the second channel would need some refactoring. And three currently missing features are provided here as a patch. Things which aren't done are save and recall (and beeper control). Hannu Vuolasaho
From 3102697f0fc5396a457ae74280ca8f7e56790cd3 Mon Sep 17 00:00:00 2001 From: Hannu Vuolasaho <vuokkose...@gmail.com> Date: Wed, 21 Oct 2015 19:04:37 +0300 Subject: [PATCH 1/2] Support for regulation status and fix for mysterious M 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 | 8 ++++++++ src/hardware/korad-kdxxxxp/protocol.c | 12 +++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/hardware/korad-kdxxxxp/api.c b/src/hardware/korad-kdxxxxp/api.c index 107bdc4..4a6c817 100644 --- a/src/hardware/korad-kdxxxxp/api.c +++ b/src/hardware/korad-kdxxxxp/api.c @@ -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; } diff --git a/src/hardware/korad-kdxxxxp/protocol.c b/src/hardware/korad-kdxxxxp/protocol.c index cd266e2..eb52810 100644 --- a/src/hardware/korad-kdxxxxp/protocol.c +++ b/src/hardware/korad-kdxxxxp/protocol.c @@ -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); -- 2.6.1
From 4bb437c019e88b298a72e9006a5321bf0613684f Mon Sep 17 00:00:00 2001 From: Hannu Vuolasaho <vuokkose...@gmail.com> Date: Thu, 22 Oct 2015 01:05:37 +0300 Subject: [PATCH 2/2] Over voltage and current protection support Developed against Velleman LABPS3005D and seems to work. --- src/hardware/korad-kdxxxxp/api.c | 22 ++++++++++++++++++++++ src/hardware/korad-kdxxxxp/protocol.c | 28 +++++++++++++++++++++++----- src/hardware/korad-kdxxxxp/protocol.h | 4 ++++ 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/hardware/korad-kdxxxxp/api.c b/src/hardware/korad-kdxxxxp/api.c index 4a6c817..6cbde4d 100644 --- a/src/hardware/korad-kdxxxxp/api.c +++ b/src/hardware/korad-kdxxxxp/api.c @@ -44,6 +44,8 @@ static const uint32_t devopts[] = { 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, + SR_CONF_OVER_CURRENT_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET, + SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET, }; static const struct korad_kdxxxxp_model models[] = { @@ -225,6 +227,12 @@ static int config_get(uint32_t key, GVariant **data, else *data = g_variant_new_string("CV"); break; + case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED: + *data = g_variant_new_boolean(devc->OCP_enabled); + break; + case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED: + *data = g_variant_new_boolean(devc->OVP_enabled); + break; default: return SR_ERR_NA; } @@ -283,6 +291,20 @@ static int config_set(uint32_t key, GVariant *data, if (korad_kdxxxxp_set_value(sdi->conn, devc) < 0) return SR_ERR; break; + case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED: + bval = g_variant_get_boolean(data); + devc->OCP_enabled = bval; + devc->target = KDXXXXP_OCP; + if (korad_kdxxxxp_set_value(sdi->conn, devc) < 0) + return SR_ERR; + break; + case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED: + bval = g_variant_get_boolean(data); + devc->OVP_enabled = bval; + devc->target = KDXXXXP_OVP; + if (korad_kdxxxxp_set_value(sdi->conn, devc) < 0) + return SR_ERR; + break; default: return SR_ERR_NA; } diff --git a/src/hardware/korad-kdxxxxp/protocol.c b/src/hardware/korad-kdxxxxp/protocol.c index eb52810..bee02d9 100644 --- a/src/hardware/korad-kdxxxxp/protocol.c +++ b/src/hardware/korad-kdxxxxp/protocol.c @@ -109,6 +109,14 @@ SR_PRIV int korad_kdxxxxp_set_value(struct sr_serial_dev_inst *serial, cmd = "BEEP%01.0f"; value = (devc->beep_enabled) ? 1 : 0; break; + case KDXXXXP_OCP: + cmd = "OCP%01.0f"; + value = (devc->OCP_enabled) ? 1 : 0; + break; + case KDXXXXP_OVP: + cmd = "OVP%01.0f"; + value = (devc->OVP_enabled) ? 1 : 0; + break; case KDXXXXP_SAVE: cmd = "SAV%01.0f"; if (devc->program < 1 || devc->program > 5) { @@ -266,18 +274,24 @@ SR_PRIV int korad_kdxxxxp_get_reply(struct sr_serial_dev_inst *serial, * 00 independent 01 series 11 parallel */ devc->beep_enabled = (1 << 4); - /* status_byte & (1 << 5) Unlocked */ - + devc->OCP_enabled = (status_byte & (1 << 5)); devc->output_enabled = (status_byte & (1 << 6)); + /* Velleman LABPS3005 quirk */ + if (devc->output_enabled) + devc->OVP_enabled = (status_byte & (1 << 7)); sr_dbg("Status: 0x%02x", status_byte); - sr_spew("Status: CH1: constant %s CH2: constant %s. Device is " - "%s and %s. Buttons are %s. Output is %s ", + 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.", (status_byte & (1 << 0)) ? "voltage" : "current", (status_byte & (1 << 1)) ? "voltage" : "current", + (status_byte & (1 << 2)) ? "parallel" : "series", (status_byte & (1 << 3)) ? "tracking" : "independent", (status_byte & (1 << 4)) ? "beeping" : "silent", (status_byte & (1 << 5)) ? "locked" : "unlocked", - (status_byte & (1 << 6)) ? "enabled" : "disabled"); + (status_byte & (1 << 6)) ? "enabled" : "disabled", + (status_byte & (1 << 7)) ? "true" : "false"); } devc->reply_pending = FALSE; @@ -300,6 +314,10 @@ static void next_measurement(struct dev_context *devc) case KDXXXXP_VOLTAGE_MAX: devc->target = KDXXXXP_CURRENT; break; + /* Read back what was set */ + case KDXXXXP_BEEP: + case KDXXXXP_OCP: + case KDXXXXP_OVP: case KDXXXXP_OUTPUT: devc->target = KDXXXXP_STATUS; break; diff --git a/src/hardware/korad-kdxxxxp/protocol.h b/src/hardware/korad-kdxxxxp/protocol.h index 3b5c2b1..c292dab 100644 --- a/src/hardware/korad-kdxxxxp/protocol.h +++ b/src/hardware/korad-kdxxxxp/protocol.h @@ -61,6 +61,8 @@ enum { KDXXXXP_STATUS, KDXXXXP_OUTPUT, KDXXXXP_BEEP, + KDXXXXP_OCP, + KDXXXXP_OVP, KDXXXXP_SAVE, KDXXXXP_RECALL, }; @@ -89,6 +91,8 @@ struct dev_context { gboolean output_enabled; /**< Is the output enabled? */ gboolean beep_enabled; /**< Enable beeper. */ + gboolean OCP_enabled; /**< Output current protection enabled */ + gboolean OVP_enabled; /**< Output voltage protection enabled */ /* Temporary state across callbacks */ int target; /**< What reply to expect */ -- 2.6.1
------------------------------------------------------------------------------
_______________________________________________ sigrok-devel mailing list sigrok-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sigrok-devel