X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fgmc-mh-1x-2x%2Fapi.c;h=5f029a9e9970e97a272b2bda5005322c96175966;hb=deb7615262ac4f9cc0750a08351afa7cbf9c34d5;hp=7a54aa68207d15246e4ea0de97977318ac340160;hpb=b15ff1c92aabeea04649de25a3a01f851ab0a1ec;p=libsigrok.git diff --git a/src/hardware/gmc-mh-1x-2x/api.c b/src/hardware/gmc-mh-1x-2x/api.c index 7a54aa68..5f029a9e 100644 --- a/src/hardware/gmc-mh-1x-2x/api.c +++ b/src/hardware/gmc-mh-1x-2x/api.c @@ -102,6 +102,7 @@ static enum model scan_model_sm(struct sr_serial_dev_inst *serial) * Try to find message consisting of device code and several * (at least 4) data bytes. */ + serial_flush(serial); for (bytecnt = 0; bytecnt < 100; bytecnt++) { byte = read_byte(serial, timeout_us); if ((byte == -1) || (timeout_us < g_get_monotonic_time())) @@ -175,8 +176,6 @@ static GSList *scan_1x_2x_rs232(struct sr_dev_driver *di, GSList *options) return NULL; } - serial_flush(serial); - model = scan_model_sm(serial); /* @@ -187,10 +186,8 @@ static GSList *scan_1x_2x_rs232(struct sr_dev_driver *di, GSList *options) serialcomm = SERIALCOMM_1X_RS232; g_free(serial->serialcomm); serial->serialcomm = g_strdup(serialcomm); - if (serial_set_paramstr(serial, serialcomm) == SR_OK) { - serial_flush(serial); + if (serial_set_paramstr(serial, serialcomm) == SR_OK) model = scan_model_sm(serial); - } } if (model != METRAHIT_NONE) { @@ -300,11 +297,9 @@ static GSList *scan_2x_bd232(struct sr_dev_driver *di, GSList *options) } }; - /* Free last alloc if no device found */ - if (devc->model == METRAHIT_NONE) { - g_free(devc); - sr_dev_inst_free(sdi); - } + /* Free last alloc that was done in preparation. */ + g_free(devc); + sr_dev_inst_free(sdi); return std_scan_complete(di, devices); @@ -327,8 +322,8 @@ static int dev_close(struct sr_dev_inst *sdi) return std_serial_dev_close(sdi); } -static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, - const struct sr_channel_group *cg) +static int config_get(uint32_t key, GVariant **data, + const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { struct dev_context *devc; @@ -354,15 +349,15 @@ static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *s } /** Implementation of config_list for Metrahit 1x/2x send mode */ -static int config_list_sm(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, - const struct sr_channel_group *cg) +static int config_list_sm(uint32_t key, GVariant **data, + const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts_sm); } /** Implementation of config_list for Metrahit 2x bidirectional mode */ -static int config_list_bd(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi, - const struct sr_channel_group *cg) +static int config_list_bd(uint32_t key, GVariant **data, + const struct sr_dev_inst *sdi, const struct sr_channel_group *cg) { return STD_CONFIG_LIST(key, data, sdi, cg, scanopts, drvopts, devopts_bd); }