X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fagilent-dmm%2Fapi.c;h=0e2bc7d8a357b459342c3935d1eb790b14a326f0;hb=4e172b8f8d725667d632484f340b1eec47597097;hp=848e2dcf6b574db62eeb0d8a6dcc9d8f8c16133e;hpb=69b07d14db24055d23bbb4c4cc718ec073ece0b7;p=libsigrok.git diff --git a/hardware/agilent-dmm/api.c b/hardware/agilent-dmm/api.c index 848e2dcf..0e2bc7d8 100644 --- a/hardware/agilent-dmm/api.c +++ b/hardware/agilent-dmm/api.c @@ -51,14 +51,18 @@ extern const struct agdmm_recv agdmm_recvs_u123x[]; extern const struct agdmm_job agdmm_jobs_u125x[]; extern const struct agdmm_recv agdmm_recvs_u125x[]; +/* This works on all the Agilent U12xxA series, although the + * U127xA can apparently also run at 19200/8n1. */ +#define SERIALCOMM "9600/8n1" + static const struct agdmm_profile supported_agdmm[] = { - { AGILENT_U1231A, "U1231A", 9600, agdmm_jobs_u123x, agdmm_recvs_u123x }, - { AGILENT_U1232A, "U1232A", 9600, agdmm_jobs_u123x, agdmm_recvs_u123x }, - { AGILENT_U1233A, "U1233A", 9600, agdmm_jobs_u123x, agdmm_recvs_u123x }, - { AGILENT_U1251A, "U1251A", 9600, agdmm_jobs_u125x, agdmm_recvs_u125x }, - { AGILENT_U1252A, "U1252A", 9600, agdmm_jobs_u125x, agdmm_recvs_u125x }, - { AGILENT_U1253A, "U1253A", 9600, agdmm_jobs_u125x, agdmm_recvs_u125x }, - { 0, NULL, 0, NULL, NULL } + { AGILENT_U1231A, "U1231A", agdmm_jobs_u123x, agdmm_recvs_u123x }, + { AGILENT_U1232A, "U1232A", agdmm_jobs_u123x, agdmm_recvs_u123x }, + { AGILENT_U1233A, "U1233A", agdmm_jobs_u123x, agdmm_recvs_u123x }, + { AGILENT_U1251A, "U1251A", agdmm_jobs_u125x, agdmm_recvs_u125x }, + { AGILENT_U1252A, "U1252A", agdmm_jobs_u125x, agdmm_recvs_u125x }, + { AGILENT_U1253A, "U1253A", agdmm_jobs_u125x, agdmm_recvs_u125x }, + { 0, NULL, NULL, NULL } }; SR_PRIV struct sr_dev_driver agdmm_driver_info; @@ -104,48 +108,6 @@ static int hw_init(void) 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; @@ -174,7 +136,7 @@ static GSList *hw_scan(GSList *options) break; } } - if (!conn || !serialcomm) + if (!conn) return NULL; if ((fd = serial_open(conn, O_RDWR|O_NONBLOCK)) == -1) { @@ -182,6 +144,8 @@ static GSList *hw_scan(GSList *options) return NULL; } + if (!serialcomm) + serialcomm = SERIALCOMM; if (serial_set_paramstr(fd, serialcomm) != SR_OK) { sr_err("Unable to set serial parameters: %s.", strerror(errno)); @@ -200,7 +164,7 @@ static GSList *hw_scan(GSList *options) sr_err("Serial buffer malloc failed."); return NULL; } - serial_readline2(fd, &buf, &len, 150); + serial_readline(fd, &buf, &len, 150); if (!len) return NULL; @@ -262,8 +226,7 @@ static int hw_dev_open(struct sr_dev_inst *sdi) devc->serial->port); return SR_ERR; } - serial_set_params(devc->serial->fd, devc->profile->serial_speed, 8, - SERIAL_PARITY_NONE, 1, 0); + serial_set_paramstr(devc->serial->fd, SERIALCOMM); sdi->status = SR_ST_ACTIVE; return SR_OK;