/*
- * This file is part of the sigrok project.
+ * This file is part of the libsigrok project.
*
* Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
*
{
struct sr_dev_inst *sdi;
struct dev_context *devc;
+ struct sr_serial_dev_inst *serial;
int len;
+ (void)fd;
+
if (!(sdi = cb_data))
return TRUE;
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(fd, devc->buf + devc->buflen, 1);
+ len = serial_read(serial, devc->buf + devc->buflen, 1);
if (len < 1)
break;
devc->buflen += len;
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;
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->fd, 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;
}
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;
return SR_OK;
if (!strcmp(g_match_info_get_string(match), "+9.90000000E+37")) {
- /* An invalid measurement shows up on the display as "O.L, but
+ /* An invalid measurement shows up on the display as "O.L", but
* comes through like this. Since comparing 38-digit floats
* is rather problematic, we'll cut through this here. */
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;
}
analog.mq = devc->cur_mq;
analog.unit = devc->cur_unit;
analog.mqflags = devc->cur_mqflags;
+ analog.probes = sdi->probes;
analog.num_samples = 1;
analog.data = &fvalue;
packet.type = SR_DF_ANALOG;