X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fagilent-dmm%2Fapi.c;h=167d4cc83cdb44d89cd547eb7ea7ae6a01f11897;hb=5edc02c77c3576a47ee85241f32785cdf0fdddf8;hp=ddc22ee9f9d428d2ac343a063308957c3d03cfc9;hpb=74ac7d7f735011012fb942577e38ddfe64738c8d;p=libsigrok.git diff --git a/hardware/agilent-dmm/api.c b/hardware/agilent-dmm/api.c index ddc22ee9..167d4cc8 100644 --- a/hardware/agilent-dmm/api.c +++ b/hardware/agilent-dmm/api.c @@ -41,11 +41,6 @@ static const int hwcaps[] = { 0, }; -static const char *probe_names[] = { - "Probe", - NULL, -}; - extern const struct agdmm_job agdmm_jobs_u123x[]; extern const struct agdmm_recv agdmm_recvs_u123x[]; extern const struct agdmm_job agdmm_jobs_u125x[]; @@ -94,7 +89,7 @@ static int clear_instances(void) return SR_OK; } -static int hw_init(void) +static int hw_init(struct sr_context *sr_ctx) { struct drv_context *drvc; @@ -103,53 +98,12 @@ static int hw_init(void) return SR_ERR_MALLOC; } + drvc->sr_ctx = sr_ctx; di->priv = drvc; return SR_OK; } -/* TODO: Merge into serial_readline() from serial.c. */ -static int serial_readline2(int fd, char **buf, int *buflen, uint64_t timeout_ms) -{ - uint64_t start; - int maxlen, len; - - timeout_ms *= 1000; - start = g_get_monotonic_time(); - - maxlen = *buflen; - *buflen = len = 0; - while(1) { - len = maxlen - *buflen - 1; - if (len < 1) - break; - len = serial_read(fd, *buf + *buflen, len); - if (len > 0) { - *buflen += len; - *(*buf + *buflen) = '\0'; - if (*buflen > 0 && *(*buf + *buflen - 1) == '\n') - /* End of line */ - break; - } - if (g_get_monotonic_time() - start > timeout_ms) - /* Timeout */ - break; - g_usleep(2000); - } - - /* Strip CRLF */ - while (*buflen) { - if (*(*buf + *buflen - 1) == '\r' || *(*buf + *buflen - 1) == '\n') - *(*buf + --*buflen) = '\0'; - else - break; - } - if (*buflen) - sr_dbg("Received '%s'.", *buf); - - return SR_OK; -} - static GSList *hw_scan(GSList *options) { struct sr_dev_inst *sdi; @@ -157,8 +111,9 @@ static GSList *hw_scan(GSList *options) struct dev_context *devc; struct sr_hwopt *opt; struct sr_probe *probe; + struct sr_serial_dev_inst *serial; GSList *l, *devices; - int len, fd, i; + int len, i; const char *conn, *serialcomm; char *buf, **tokens; @@ -180,22 +135,17 @@ static GSList *hw_scan(GSList *options) } if (!conn) return NULL; + if (!serialcomm) + serialcomm = SERIALCOMM; - if ((fd = serial_open(conn, O_RDWR|O_NONBLOCK)) == -1) { - sr_err("Unable to open %s: %s.", conn, strerror(errno)); + if (!(serial = sr_serial_dev_inst_new(conn, serialcomm))) return NULL; - } - if (!serialcomm) - serialcomm = SERIALCOMM; - if (serial_set_paramstr(fd, serialcomm) != SR_OK) { - sr_err("Unable to set serial parameters: %s.", - strerror(errno)); + if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) return NULL; - } - serial_flush(fd); - if (serial_write(fd, "*IDN?\r\n", 7) == -1) { + serial_flush(serial); + if (serial_write(serial, "*IDN?\r\n", 7) == -1) { sr_err("Unable to send identification string: %s.", strerror(errno)); return NULL; @@ -206,7 +156,7 @@ static GSList *hw_scan(GSList *options) sr_err("Serial buffer malloc failed."); return NULL; } - serial_readline2(fd, &buf, &len, 150); + serial_readline(serial, &buf, &len, 150); if (!len) return NULL; @@ -224,7 +174,7 @@ static GSList *hw_scan(GSList *options) return NULL; } devc->profile = &supported_agdmm[i]; - devc->serial = sr_serial_dev_inst_new(conn, -1); + devc->serial = serial; devc->cur_mq = -1; sdi->priv = devc; sdi->driver = di; @@ -239,7 +189,9 @@ static GSList *hw_scan(GSList *options) g_strfreev(tokens); g_free(buf); - serial_close(fd); + serial_close(serial); + if (!devices) + sr_serial_dev_inst_free(serial); return devices; } @@ -262,13 +214,9 @@ static int hw_dev_open(struct sr_dev_inst *sdi) return SR_ERR_BUG; } - devc->serial->fd = serial_open(devc->serial->port, O_RDWR | O_NONBLOCK); - if (devc->serial->fd == -1) { - sr_err("Couldn't open serial port '%s'.", - devc->serial->port); + if (serial_open(devc->serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) return SR_ERR; - } - serial_set_paramstr(devc->serial->fd, SERIALCOMM); + sdi->status = SR_ST_ACTIVE; return SR_OK; @@ -284,8 +232,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi) } if (devc->serial && devc->serial->fd != -1) { - serial_close(devc->serial->fd); - devc->serial->fd = -1; + serial_close(devc->serial); sdi->status = SR_ST_INACTIVE; } @@ -303,7 +250,6 @@ static int hw_cleanup(void) static int hw_info_get(int info_id, const void **data, const struct sr_dev_inst *sdi) { - (void)sdi; switch (info_id) { @@ -313,12 +259,6 @@ static int hw_info_get(int info_id, const void **data, case SR_DI_HWCAPS: *data = hwcaps; break; - case SR_DI_NUM_PROBES: - *data = GINT_TO_POINTER(1); - break; - case SR_DI_PROBE_NAMES: - *data = probe_names; - break; default: return SR_ERR_ARG; }