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];
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);
goto scan_cleanup;
}
- len = 128;
+ len = sizeof(buf);
ret = brymen_stream_detect(serial, buf, &len, brymen_packet_length,
brymen_packet_is_valid, 1000, 9600);
if (ret != SR_OK)
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) {
if (!conn)
return NULL;
- if (serialcomm) {
- /* Use the provided comm specs. */
- devices = brymen_scan(di, conn, serialcomm);
- } else {
- /* But 9600/8n1 should work all of the time. */
- devices = brymen_scan(di, conn, "9600/8n1/dtr=1/rts=1");
- }
+ devices = brymen_scan(di, conn, serialcomm);
return devices;
}
-static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sdi,
- const struct sr_channel_group *cg)
+static int config_set(uint32_t key, GVariant *data,
+ const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{
struct dev_context *devc;
return sr_sw_limits_config_set(&devc->sw_limits, key, data);
}
-static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
- const struct sr_channel_group *cg)
+static int config_list(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);
}
sr_sw_limits_acquisition_start(&devc->sw_limits);
std_session_send_df_header(sdi);
- /* Poll every 50ms, or whenever some data comes in. */
serial = sdi->conn;
serial_source_add(sdi->session, serial, G_IO_IN, 50,
brymen_dmm_receive_data, (void *)sdi);