X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=blobdiff_plain;f=src%2Fhardware%2Fbrymen-dmm%2Fapi.c;h=dacbee889267f7949e4e18ca08daa20ef31110b3;hp=ce6f1f33e4f4c8e832fa34232a74f04698d89f13;hb=11addc897a86a039f72cefbebb5058611ad79102;hpb=00ed77f27c85462cae238ee433dbf0f606eaaf84 diff --git a/src/hardware/brymen-dmm/api.c b/src/hardware/brymen-dmm/api.c index ce6f1f33..dacbee88 100644 --- a/src/hardware/brymen-dmm/api.c +++ b/src/hardware/brymen-dmm/api.c @@ -41,6 +41,7 @@ static GSList *brymen_scan(struct sr_dev_driver *di, const char *conn, struct sr_dev_inst *sdi; struct dev_context *devc; struct sr_serial_dev_inst *serial; + int rts_toggle_delay_us; GSList *devices; int ret; uint8_t buf[128]; @@ -50,6 +51,21 @@ static GSList *brymen_scan(struct sr_dev_driver *di, const char *conn, if (serial_open(serial, SERIAL_RDWR) != SR_OK) return NULL; + /* + * The device requires an RTS *pulse* before communication. + * The vendor's documentation recommends the following sequence: + * Open the COM port, wait for 100ms, set RTS=1, wait for 100ms, + * set RTS=0, wait for 100ms, set RTS=1, configure bitrate and + * frame format, transmit request data, receive response data. + */ + rts_toggle_delay_us = 100 * 1000; /* 100ms */ + g_usleep(rts_toggle_delay_us); + serial_set_handshake(serial, 1, -1); + g_usleep(rts_toggle_delay_us); + serial_set_handshake(serial, 0, -1); + g_usleep(rts_toggle_delay_us); + serial_set_handshake(serial, 1, -1); + g_usleep(rts_toggle_delay_us); sr_info("Probing port %s.", conn); @@ -95,7 +111,12 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) devices = NULL; - conn = serialcomm = NULL; + /* + * BEWARE! Default 'conn' is not desirable when the device cannot + * reliably get detected. Insist that users specify the port. + */ + conn = NULL; + serialcomm = "9600/8n1/dtr=1/rts=1"; for (l = options; l; l = l->next) { src = l->data; switch (src->key) { @@ -110,10 +131,7 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) if (!conn) return NULL; - if (serialcomm) - devices = brymen_scan(di, conn, serialcomm); - else - devices = brymen_scan(di, conn, "9600/8n1/dtr=1/rts=1"); + devices = brymen_scan(di, conn, serialcomm); return devices; }