X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Ffluke-dmm%2Fapi.c;h=a7272ad960e8adf8c878483a9637e7ba18632662;hb=5edc02c77c3576a47ee85241f32785cdf0fdddf8;hp=2c82d92d0568434294074b55739d8f3517c2f982;hpb=886a52b6fbffb0fd06849c928cf9fd31a0d4657b;p=libsigrok.git diff --git a/hardware/fluke-dmm/api.c b/hardware/fluke-dmm/api.c index 2c82d92d..a7272ad9 100644 --- a/hardware/fluke-dmm/api.c +++ b/hardware/fluke-dmm/api.c @@ -41,17 +41,23 @@ static const int hwcaps[] = { 0, }; -static const char *probe_names[] = { - "Probe", - NULL, -}; - SR_PRIV struct sr_dev_driver flukedmm_driver_info; static struct sr_dev_driver *di = &flukedmm_driver_info; +static char *scan_conn[] = { + /* 287/289 */ + "115200/8n1", + /* 187/189 */ + "9600/8n1", + /* Scopemeter 190 series */ + "1200/8n1", + NULL +}; + static const struct flukedmm_profile supported_flukedmm[] = { - { FLUKE_187, "187", 100 }, - { FLUKE_287, "287", 100 }, + { FLUKE_187, "187", 100, 1000 }, + { FLUKE_287, "287", 100, 1000 }, + { FLUKE_190, "199B", 1000, 3500 }, }; @@ -81,7 +87,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; @@ -90,6 +96,7 @@ static int hw_init(void) return SR_ERR_MALLOC; } + drvc->sr_ctx = sr_ctx; di->priv = drvc; return SR_OK; @@ -101,18 +108,16 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm) struct drv_context *drvc; struct dev_context *devc; struct sr_probe *probe; + struct sr_serial_dev_inst *serial; GSList *devices; - int fd, retry, len, i, s; + int retry, len, i, s; char buf[128], *b, **tokens; - 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 (serial_set_paramstr(fd, serialcomm) != SR_OK) { - sr_err("Unable to set serial parameters."); + + if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) return NULL; - } drvc = di->priv; b = buf; @@ -122,8 +127,8 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm) * is not in an idle state when we send ID. */ while (!devices && retry < 3) { retry++; - serial_flush(fd); - if (serial_write(fd, "ID\r", 3) == -1) { + serial_flush(serial); + if (serial_write(serial, "ID\r", 3) == -1) { sr_err("Unable to send ID string: %s.", strerror(errno)); continue; @@ -132,7 +137,7 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm) /* Response is first a CMD_ACK byte (ASCII '0' for OK, * or '1' to signify an error. */ len = 128; - serial_readline(fd, &b, &len, 150); + serial_readline(serial, &b, &len, 150); if (len != 1) continue; if (buf[0] != '0') @@ -140,10 +145,15 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm) /* If CMD_ACK was OK, ID string follows. */ len = 128; - serial_readline(fd, &b, &len, 150); + serial_readline(serial, &b, &len, 850); if (len < 10) continue; - tokens = g_strsplit(buf, ",", 3); + if (strcspn(buf, ",") < 15) + /* Looks like it's comma-separated. */ + tokens = g_strsplit(buf, ",", 3); + else + /* Fluke 199B, at least, uses semicolon. */ + tokens = g_strsplit(buf, ";", 3); if (!strncmp("FLUKE", tokens[0], 5) && tokens[1] && tokens[2]) { for (i = 0; supported_flukedmm[i].model; i++) { @@ -159,8 +169,7 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm) return NULL; } devc->profile = &supported_flukedmm[i]; - devc->serial = sr_serial_dev_inst_new(conn, -1); - devc->serialcomm = g_strdup(serialcomm); + devc->serial = serial; sdi->priv = devc; sdi->driver = di; if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "P1"))) @@ -172,8 +181,13 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm) } } g_strfreev(tokens); + if (devices) + /* Found one. */ + break; } - serial_close(fd); + serial_close(serial); + if (!devices) + sr_serial_dev_inst_free(serial); return devices; } @@ -182,6 +196,7 @@ static GSList *hw_scan(GSList *options) { struct sr_hwopt *opt; GSList *l, *devices; + int i; const char *conn, *serialcomm; conn = serialcomm = NULL; @@ -203,11 +218,13 @@ static GSList *hw_scan(GSList *options) /* Use the provided comm specs. */ devices = fluke_scan(conn, serialcomm); } else { - /* Try 115200, as used on 287/289. */ - devices = fluke_scan(conn, "115200/8n1"); - if (!devices) - /* Fall back to 9600 for 187/189. */ - devices = fluke_scan(conn, "9600/8n1"); + for (i = 0; scan_conn[i]; i++) { + if ((devices = fluke_scan(conn, scan_conn[i]))) + break; + /* The Scopemeter 199B, at least, requires this + * after all the 115k/9.6k confusion. */ + g_usleep(5000); + } } return devices; @@ -231,15 +248,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); - return SR_ERR; - } - if (serial_set_paramstr(devc->serial->fd, devc->serialcomm) != SR_OK) { - sr_err("Unable to set serial parameters."); + if (serial_open(devc->serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) return SR_ERR; - } + sdi->status = SR_ST_ACTIVE; return SR_OK; @@ -255,8 +266,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; } @@ -274,7 +284,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) { @@ -284,12 +293,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; } @@ -370,7 +373,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, /* Poll every 100ms, or whenever some data comes in. */ sr_source_add(devc->serial->fd, G_IO_IN, 50, fluke_receive_data, (void *)sdi); - if (serial_write(devc->serial->fd, "QM\r", 3) == -1) { + if (serial_write(devc->serial, "QM\r", 3) == -1) { sr_err("Unable to send QM: %s.", strerror(errno)); return SR_ERR; } @@ -380,8 +383,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi, return SR_OK; } -static int hw_dev_acquisition_stop(const struct sr_dev_inst *sdi, - void *cb_data) +static int hw_dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) { struct sr_datafeed_packet packet; struct dev_context *devc;