fluke-dmm: use new serial API
This commit is contained in:
parent
530f201eb8
commit
58d03f034f
|
@ -101,18 +101,16 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm)
|
||||||
struct drv_context *drvc;
|
struct drv_context *drvc;
|
||||||
struct dev_context *devc;
|
struct dev_context *devc;
|
||||||
struct sr_probe *probe;
|
struct sr_probe *probe;
|
||||||
|
struct sr_serial_dev_inst *serial;
|
||||||
GSList *devices;
|
GSList *devices;
|
||||||
int fd, retry, len, i, s;
|
int retry, len, i, s;
|
||||||
char buf[128], *b, **tokens;
|
char buf[128], *b, **tokens;
|
||||||
|
|
||||||
if ((fd = serial_open(conn, O_RDWR|O_NONBLOCK)) == -1) {
|
if (!(serial = sr_serial_dev_inst_new(conn, serialcomm)))
|
||||||
sr_err("Unable to open %s: %s.", conn, strerror(errno));
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
if (serial_set_paramstr(fd, serialcomm) != SR_OK) {
|
if (serial_open(serial, O_RDWR|O_NONBLOCK) != SR_OK)
|
||||||
sr_err("Unable to set serial parameters.");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
drvc = di->priv;
|
drvc = di->priv;
|
||||||
b = buf;
|
b = buf;
|
||||||
|
@ -122,8 +120,8 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm)
|
||||||
* is not in an idle state when we send ID. */
|
* is not in an idle state when we send ID. */
|
||||||
while (!devices && retry < 3) {
|
while (!devices && retry < 3) {
|
||||||
retry++;
|
retry++;
|
||||||
serial_flush(fd);
|
serial_flush(serial);
|
||||||
if (serial_write(fd, "ID\r", 3) == -1) {
|
if (serial_write(serial, "ID\r", 3) == -1) {
|
||||||
sr_err("Unable to send ID string: %s.",
|
sr_err("Unable to send ID string: %s.",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
continue;
|
continue;
|
||||||
|
@ -132,7 +130,7 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm)
|
||||||
/* Response is first a CMD_ACK byte (ASCII '0' for OK,
|
/* Response is first a CMD_ACK byte (ASCII '0' for OK,
|
||||||
* or '1' to signify an error. */
|
* or '1' to signify an error. */
|
||||||
len = 128;
|
len = 128;
|
||||||
serial_readline(fd, &b, &len, 150);
|
serial_readline(serial, &b, &len, 150);
|
||||||
if (len != 1)
|
if (len != 1)
|
||||||
continue;
|
continue;
|
||||||
if (buf[0] != '0')
|
if (buf[0] != '0')
|
||||||
|
@ -140,7 +138,7 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm)
|
||||||
|
|
||||||
/* If CMD_ACK was OK, ID string follows. */
|
/* If CMD_ACK was OK, ID string follows. */
|
||||||
len = 128;
|
len = 128;
|
||||||
serial_readline(fd, &b, &len, 150);
|
serial_readline(serial, &b, &len, 150);
|
||||||
if (len < 10)
|
if (len < 10)
|
||||||
continue;
|
continue;
|
||||||
tokens = g_strsplit(buf, ",", 3);
|
tokens = g_strsplit(buf, ",", 3);
|
||||||
|
@ -159,8 +157,7 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
devc->profile = &supported_flukedmm[i];
|
devc->profile = &supported_flukedmm[i];
|
||||||
devc->serial = sr_serial_dev_inst_new(conn, -1);
|
devc->serial = serial;
|
||||||
devc->serialcomm = g_strdup(serialcomm);
|
|
||||||
sdi->priv = devc;
|
sdi->priv = devc;
|
||||||
sdi->driver = di;
|
sdi->driver = di;
|
||||||
if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "P1")))
|
if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, "P1")))
|
||||||
|
@ -173,7 +170,9 @@ static GSList *fluke_scan(const char *conn, const char *serialcomm)
|
||||||
}
|
}
|
||||||
g_strfreev(tokens);
|
g_strfreev(tokens);
|
||||||
}
|
}
|
||||||
serial_close(fd);
|
serial_close(serial);
|
||||||
|
if (!devices)
|
||||||
|
sr_serial_dev_inst_free(serial);
|
||||||
|
|
||||||
return devices;
|
return devices;
|
||||||
}
|
}
|
||||||
|
@ -231,15 +230,9 @@ static int hw_dev_open(struct sr_dev_inst *sdi)
|
||||||
return SR_ERR_BUG;
|
return SR_ERR_BUG;
|
||||||
}
|
}
|
||||||
|
|
||||||
devc->serial->fd = serial_open(devc->serial->port, O_RDWR | O_NONBLOCK);
|
if (serial_open(devc->serial, O_RDWR|O_NONBLOCK) != SR_OK)
|
||||||
if (devc->serial->fd == -1) {
|
|
||||||
sr_err("Couldn't open serial port '%s'.", devc->serial->port);
|
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
}
|
|
||||||
if (serial_set_paramstr(devc->serial->fd, devc->serialcomm) != SR_OK) {
|
|
||||||
sr_err("Unable to set serial parameters.");
|
|
||||||
return SR_ERR;
|
|
||||||
}
|
|
||||||
sdi->status = SR_ST_ACTIVE;
|
sdi->status = SR_ST_ACTIVE;
|
||||||
|
|
||||||
return SR_OK;
|
return SR_OK;
|
||||||
|
@ -255,8 +248,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (devc->serial && devc->serial->fd != -1) {
|
if (devc->serial && devc->serial->fd != -1) {
|
||||||
serial_close(devc->serial->fd);
|
serial_close(devc->serial);
|
||||||
devc->serial->fd = -1;
|
|
||||||
sdi->status = SR_ST_INACTIVE;
|
sdi->status = SR_ST_INACTIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,7 +362,7 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
|
||||||
/* Poll every 100ms, or whenever some data comes in. */
|
/* Poll every 100ms, or whenever some data comes in. */
|
||||||
sr_source_add(devc->serial->fd, G_IO_IN, 50, fluke_receive_data, (void *)sdi);
|
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));
|
sr_err("Unable to send QM: %s.", strerror(errno));
|
||||||
return SR_ERR;
|
return SR_ERR;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,6 @@ struct dev_context {
|
||||||
uint64_t limit_samples;
|
uint64_t limit_samples;
|
||||||
uint64_t limit_msec;
|
uint64_t limit_msec;
|
||||||
struct sr_serial_dev_inst *serial;
|
struct sr_serial_dev_inst *serial;
|
||||||
char *serialcomm;
|
|
||||||
|
|
||||||
/* Opaque pointer passed in by the frontend. */
|
/* Opaque pointer passed in by the frontend. */
|
||||||
void *cb_data;
|
void *cb_data;
|
||||||
|
|
|
@ -314,6 +314,8 @@ SR_PRIV int fluke_receive_data(int fd, int revents, void *cb_data)
|
||||||
int len;
|
int len;
|
||||||
int64_t now, elapsed;
|
int64_t now, elapsed;
|
||||||
|
|
||||||
|
(void)fd;
|
||||||
|
|
||||||
if (!(sdi = cb_data))
|
if (!(sdi = cb_data))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
|
@ -323,7 +325,7 @@ SR_PRIV int fluke_receive_data(int fd, int revents, void *cb_data)
|
||||||
if (revents == G_IO_IN) {
|
if (revents == G_IO_IN) {
|
||||||
/* Serial data arrived. */
|
/* Serial data arrived. */
|
||||||
while(FLUKEDMM_BUFSIZE - devc->buflen - 1 > 0) {
|
while(FLUKEDMM_BUFSIZE - devc->buflen - 1 > 0) {
|
||||||
len = serial_read(fd, devc->buf + devc->buflen, 1);
|
len = serial_read(devc->serial, devc->buf + devc->buflen, 1);
|
||||||
if (len < 1)
|
if (len < 1)
|
||||||
break;
|
break;
|
||||||
devc->buflen++;
|
devc->buflen++;
|
||||||
|
@ -349,7 +351,7 @@ SR_PRIV int fluke_receive_data(int fd, int revents, void *cb_data)
|
||||||
if ((devc->expect_response == FALSE && elapsed > devc->profile->poll_period)
|
if ((devc->expect_response == FALSE && elapsed > devc->profile->poll_period)
|
||||||
|| elapsed > 1000) {
|
|| elapsed > 1000) {
|
||||||
sr_spew("Sending QM.");
|
sr_spew("Sending QM.");
|
||||||
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));
|
sr_err("Unable to send QM: %s.", strerror(errno));
|
||||||
devc->cmd_sent_at = now;
|
devc->cmd_sent_at = now;
|
||||||
devc->expect_response = TRUE;
|
devc->expect_response = TRUE;
|
||||||
|
|
Loading…
Reference in New Issue