X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=blobdiff_plain;f=hardware%2Fagilent-dmm%2Fsched.c;h=bd9cb3885ba2ef78d528f2a3af394b691168af18;hp=339dbac6aaf11e6a995c276c663d15fafc018cba;hb=ba7dd8bbb8168cba432a844259a3e239aa5f36d7;hpb=109a3ba4137874373b249fee90055373e13a2a1a diff --git a/hardware/agilent-dmm/sched.c b/hardware/agilent-dmm/sched.c index 339dbac6..bd9cb388 100644 --- a/hardware/agilent-dmm/sched.c +++ b/hardware/agilent-dmm/sched.c @@ -1,5 +1,5 @@ /* - * This file is part of the sigrok project. + * This file is part of the libsigrok project. * * Copyright (C) 2012 Bert Vermeulen * @@ -91,6 +91,7 @@ SR_PRIV int agdmm_receive_data(int fd, int revents, void *cb_data) { struct sr_dev_inst *sdi; struct dev_context *devc; + struct sr_serial_dev_inst *serial; int len; (void)fd; @@ -101,10 +102,11 @@ SR_PRIV int agdmm_receive_data(int fd, int revents, void *cb_data) if (!(devc = sdi->priv)) return TRUE; + serial = sdi->conn; if (revents == G_IO_IN) { /* Serial data arrived. */ while(AGDMM_BUFSIZE - devc->buflen - 1 > 0) { - len = serial_read(devc->serial, devc->buf + devc->buflen, 1); + len = serial_read(serial, devc->buf + devc->buflen, 1); if (len < 1) break; devc->buflen += len; @@ -119,7 +121,7 @@ SR_PRIV int agdmm_receive_data(int fd, int revents, void *cb_data) dispatch(sdi); - if (devc->num_samples >= devc->limit_samples) + if (devc->limit_samples && devc->num_samples >= devc->limit_samples) sdi->driver->dev_acquisition_stop(sdi, cb_data); return TRUE; @@ -127,21 +129,22 @@ SR_PRIV int agdmm_receive_data(int fd, int revents, void *cb_data) static int agdmm_send(const struct sr_dev_inst *sdi, const char *cmd) { - struct dev_context *devc; + struct sr_serial_dev_inst *serial; char buf[32]; - devc = sdi->priv; + serial = sdi->conn; + sr_spew("Sending '%s'.", cmd); strncpy(buf, cmd, 28); if (!strncmp(buf, "*IDN?", 5)) strncat(buf, "\r\n", 32); else strncat(buf, "\n\r\n", 32); - if (serial_write(devc->serial, buf, strlen(buf)) == -1) { + if (serial_write(serial, buf, strlen(buf)) == -1) { sr_err("Failed to send: %s.", strerror(errno)); return SR_ERR; } - + return SR_OK; } @@ -231,7 +234,7 @@ static int recv_fetc(const struct sr_dev_inst *sdi, GMatchInfo *match) struct sr_datafeed_packet packet; struct sr_datafeed_analog analog; float fvalue; - char *mstr, *eptr; + char *mstr; sr_spew("FETC reply '%s'.", g_match_info_get_string(match)); devc = sdi->priv; @@ -249,12 +252,12 @@ static int recv_fetc(const struct sr_dev_inst *sdi, GMatchInfo *match) fvalue = NAN; } else { mstr = g_match_info_fetch(match, 1); - fvalue = strtof(mstr, &eptr); - g_free(mstr); - if (fvalue == 0.0 && eptr == mstr) { + if (sr_atof_ascii(mstr, &fvalue) != SR_OK || fvalue == 0.0) { + g_free(mstr); sr_err("Invalid float."); return SR_ERR; } + g_free(mstr); if (devc->cur_divider > 0) fvalue /= devc->cur_divider; } @@ -263,6 +266,7 @@ static int recv_fetc(const struct sr_dev_inst *sdi, GMatchInfo *match) analog.mq = devc->cur_mq; analog.unit = devc->cur_unit; analog.mqflags = devc->cur_mqflags; + analog.channels = sdi->channels; analog.num_samples = 1; analog.data = &fvalue; packet.type = SR_DF_ANALOG;