Safer initialisation of ftdi_readstream
authorUwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de>
Thu, 20 Jan 2011 15:51:21 +0000 (16:51 +0100)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Fri, 21 Jan 2011 08:30:10 +0000 (09:30 +0100)
Applies to both branches

--
Uwe Bonnes                bon@elektron.ikp.physik.tu-darmstadt.de

src/ftdi_stream.c

index 6c40327..6b5b61c 100644 (file)
@@ -153,6 +153,20 @@ ftdi_readstream(struct ftdi_context *ftdi,
     int xferIndex;
     int err = 0;
     
+    /* We don't know in what state we are, switch to reset*/
+    if (ftdi_set_bitmode(ftdi,  0xff, BITMODE_RESET) < 0)
+    {
+        fprintf(stderr,"Can't reset mode\n");
+        return 1;
+    }
+    
+    /* Purge anything remaining in the buffers*/
+    if (ftdi_usb_purge_buffers(ftdi) < 0)
+    {
+        fprintf(stderr,"Can't Purge\n");
+        return 1;
+    }
+
     /*
      * Set up all transfers
      */