From: Richard Allen Date: Sat, 16 Jan 2021 19:31:31 +0000 (-0600) Subject: gwinstek-gpd: Retry device identification on failure X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=c329b788d297d68b2442b89c0f33b0d189132336 gwinstek-gpd: Retry device identification on failure Try the identification command up to three times if the device responds with 'Invalid Character.', which can happen if the device has buffered part of a command but not executed it. --- diff --git a/src/hardware/gwinstek-gpd/api.c b/src/hardware/gwinstek-gpd/api.c index 5bf0ce52..6e745ee4 100644 --- a/src/hardware/gwinstek-gpd/api.c +++ b/src/hardware/gwinstek-gpd/api.c @@ -21,6 +21,8 @@ #include #include "protocol.h" +#define IDN_RETRIES 3 /* at least 2 */ + static const uint32_t scanopts[] = { SR_CONF_CONN, SR_CONF_SERIALCOMM, @@ -117,12 +119,32 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) if (serial_open(serial, SERIAL_RDWR) != SR_OK) return NULL; - gpd_send_cmd(serial, "*IDN?\n"); - if (gpd_receive_reply(serial, reply, sizeof(reply)) != SR_OK) { - sr_err("Device did not reply."); + /* + * Problem: we need to clear the GPD receive buffer before we + * can expect it to process commands correctly. + * + * Do not just send a newline, since that may cause it to + * execute a currently buffered command. + * + * Solution: Send identification request a few times. + * The first should corrupt any previous buffered command if present + * and respond with "Invalid Character." or respond directly with + * an identification string starting with "GW INSTEK" + */ + for (i = 0; i