X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=blobdiff_plain;f=src%2Fhardware%2Fgwinstek-gpd%2Fprotocol.c;h=ed218117cbcd75d71208be14bada4ccefe6e2b43;hp=ba69fed4a1fb052d22a3fab462bd24f64f25ee50;hb=1145ceaa789718e2e46ab6161c5205af3e6565c5;hpb=eaa8c6597b880d018731c36922ed4013e34813e1 diff --git a/src/hardware/gwinstek-gpd/protocol.c b/src/hardware/gwinstek-gpd/protocol.c index ba69fed4..ed218117 100644 --- a/src/hardware/gwinstek-gpd/protocol.c +++ b/src/hardware/gwinstek-gpd/protocol.c @@ -51,9 +51,9 @@ SR_PRIV int gpd_receive_reply(struct sr_serial_dev_inst *serial, char *buf, { int l_recv = 0, bufpos = 0, retc, l_startpos = 0, lines = 1; gint64 start, remaining; - const int timeout_ms = 100; + const int timeout_ms = 250; - if (!serial || (lines <= 0) || !buf || (buflen <= 0)) + if (!serial || !buf || (buflen <= 0)) return SR_ERR_ARG; start = g_get_monotonic_time(); @@ -69,7 +69,7 @@ SR_PRIV int gpd_receive_reply(struct sr_serial_dev_inst *serial, char *buf, if (bufpos == 0 && buf[bufpos] == '\n') continue; - if (buf[bufpos] == '\n') { + if (buf[bufpos] == '\n' || buf[bufpos] == '\r') { buf[bufpos] = '\0'; sr_dbg("Received line '%s'.", &buf[l_startpos]); buf[bufpos] = '\n'; @@ -126,20 +126,19 @@ SR_PRIV int gpd_receive_data(int fd, int revents, void *cb_data) g_free(reply_esc); } else { for (i = 0; i < devc->model->num_channels; i++) { + packet.type = SR_DF_ANALOG; + packet.payload = &analog; + reply[0] = '\0'; gpd_receive_reply(serial, reply, sizeof(reply)); - if (sscanf(reply, "%f", &devc->config[i].output_voltage_max) != 1) { - sr_err("Invalid reply to VOUT1?: '%s'.", + if (sscanf(reply, "%f", &devc->config[i].output_current_last) != 1) { + sr_err("Invalid reply to IOUT1?: '%s'.", reply); return TRUE; } - sr_analog_init(&analog, &encoding, &meaning, &spec, 0); - /* Send the value forward. */ - packet.type = SR_DF_ANALOG; - packet.payload = &analog; - + sr_analog_init(&analog, &encoding, &meaning, &spec, 0); analog.num_samples = 1; ch = g_slist_nth_data(sdi->channels, i); analog.meaning->channels = @@ -149,23 +148,19 @@ SR_PRIV int gpd_receive_data(int fd, int revents, void *cb_data) analog.meaning->mqflags = 0; analog.encoding->digits = 3; analog.spec->spec_digits = 3; - analog.data = &devc->config[i].output_current_max; + analog.data = &devc->config[i].output_current_last; sr_session_send(sdi, &packet); reply[0] = '\0'; gpd_receive_reply(serial, reply, sizeof(reply)); - if (sscanf(reply, "%f", &devc->config[i].output_voltage_max) != 1) { + if (sscanf(reply, "%f", &devc->config[i].output_voltage_last) != 1) { sr_err("Invalid reply to VOUT1?: '%s'.", reply); return TRUE; } - sr_analog_init(&analog, &encoding, &meaning, &spec, 0); - /* Send the value forward. */ - packet.type = SR_DF_ANALOG; - packet.payload = &analog; - + sr_analog_init(&analog, &encoding, &meaning, &spec, 0); analog.num_samples = 1; ch = g_slist_nth_data(sdi->channels, i); analog.meaning->channels = @@ -175,11 +170,12 @@ SR_PRIV int gpd_receive_data(int fd, int revents, void *cb_data) analog.meaning->mqflags = SR_MQFLAG_DC; analog.encoding->digits = 3; analog.spec->spec_digits = 3; - analog.data = &devc->config[i].output_voltage_max; + analog.data = &devc->config[i].output_voltage_last; sr_session_send(sdi, &packet); } devc->reply_pending = FALSE; + sr_sw_limits_update_samples_read(&devc->limits, 1); } } else { if (!devc->reply_pending) {