X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fkorad-kdxxxxp%2Fprotocol.c;h=bec63b4e40c5ad375a30e262ac5eebf6053b93ec;hb=ce19d4c6157b2998aa88a2f32670dd7bdcca02e8;hp=cd266e2fc718e6c5c02a0882530fb43ed9b1a187;hpb=5faebab2903dc91949edc31f0a4b118d86090a30;p=libsigrok.git diff --git a/src/hardware/korad-kdxxxxp/protocol.c b/src/hardware/korad-kdxxxxp/protocol.c index cd266e2f..bec63b4e 100644 --- a/src/hardware/korad-kdxxxxp/protocol.c +++ b/src/hardware/korad-kdxxxxp/protocol.c @@ -80,7 +80,8 @@ static void give_device_time_to_process(struct dev_context *devc) SR_PRIV int korad_kdxxxxp_set_value(struct sr_serial_dev_inst *serial, struct dev_context *devc) { - char msg[21], *cmd; + char msg[21]; + const char *cmd; float value; int ret; @@ -109,6 +110,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) { @@ -202,7 +211,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 +250,15 @@ 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); @@ -256,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; @@ -290,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;