]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/atten-pps3xxx/api.c
atten-pps3xxx: Fix serial port timeout.
[libsigrok.git] / src / hardware / atten-pps3xxx / api.c
index 75a1fbbd3e3355ce75096fed5b93fc303995c934..68dec6b08d3e15cad1d84f340eaf83b6659ef357 100644 (file)
@@ -92,6 +92,7 @@ static GSList *scan(GSList *options, int modelid)
        struct sr_serial_dev_inst *serial;
        GSList *l, *devices;
        struct pps_model *model;
+       float byte_delay_ms;
        uint8_t packet[PACKET_SIZE];
        unsigned int i;
        int ret;
@@ -126,13 +127,21 @@ static GSList *scan(GSList *options, int modelid)
                return NULL;
        serial_flush(serial);
 
-       /* This is how the vendor software channels for hardware. */
+       /* How long it takes for a byte to transfer over the serial port. */
+       if (sp_get_port_transport(serial->data) == SP_TRANSPORT_NATIVE)
+               /* 11 bits at 9600 bps. */
+               byte_delay_ms = 1.15;
+       else
+               /* Emulated serial over USB or bluetooth is just enqueueing. */
+               byte_delay_ms = 0;
+
+       /* This is how the vendor software scans for hardware. */
        memset(packet, 0, PACKET_SIZE);
        packet[0] = 0xaa;
        packet[1] = 0xaa;
-       if (serial_write_blocking(serial, packet, PACKET_SIZE) == -1) {
-               sr_err("Unable to write while probing for hardware: %s",
-                               strerror(errno));
+       if (serial_write_blocking(serial, packet, PACKET_SIZE,
+                       byte_delay_ms * PACKET_SIZE + 1) < PACKET_SIZE) {
+               sr_err("Unable to write while probing for hardware.");
                return NULL;
        }
        /* The device responds with a 24-byte packet when it receives a packet.
@@ -179,6 +188,7 @@ static GSList *scan(GSList *options, int modelid)
        devc = g_malloc0(sizeof(struct dev_context));
        devc->model = model;
        devc->config = g_malloc0(sizeof(struct per_channel_config) * model->num_channels);
+       devc->byte_delay_ms = byte_delay_ms;
        sdi->priv = devc;
        drvc->instances = g_slist_append(drvc->instances, sdi);
        devices = g_slist_append(devices, sdi);