Nick Raptis avatar Nick Raptis committed b97869c

Added FlushInput patch

Comments (0)

Files changed (2)

+# HG changeset patch
+# Parent a006ad9770f98dfb6bec9ffba3d310a6fa1a64b7
+Flush input between resets to prevent poisoning
+
+diff -r a006ad9770f9 -r bec77585be7f pyfirmata/mockup.py
+--- a/pyfirmata/mockup.py	Sun May 22 13:17:07 2011 +0200
++++ b/pyfirmata/mockup.py	Mon May 23 00:03:33 2011 +0300
+@@ -52,6 +52,9 @@
+     def close(self):
+         self.clear()
+         
++    def flushInput(self):
++        self.clear()
++        
+     def inWaiting(self):
+         return len(self)
+         
+diff -r a006ad9770f9 -r bec77585be7f pyfirmata/pyfirmata.py
+--- a/pyfirmata/pyfirmata.py	Sun May 22 13:17:07 2011 +0200
++++ b/pyfirmata/pyfirmata.py	Mon May 23 00:03:33 2011 +0300
+@@ -68,16 +68,19 @@
+     
+     def __init__(self, port, layout, baudrate=57600, name=None):
+         self.sp = serial.Serial(port, baudrate)
+-        # Allow 5 secs for Arduino's auto-reset to happen
+-        # Alas, Firmata blinks it's version before printing it to serial
+-        # For 2.3, even 5 seconds might not be enough.
++        # Allow for Arduino's auto-reset to happen
++        # and flush the buffer to prevent poisoning.
+         # TODO Find a more reliable way to wait until the board is ready
+-        self.pass_time(5)
++        self.pass_time(0.1)
++        self.sp.flushInput()
+         self.name = name
+         if not self.name:
+             self.name = port
+         self.setup_layout(layout)
+         # Iterate over the first messages to get firmware data
++        # Firmata blinks it's version before printing it to serial
++        # For 2.3, 5 seconds might not be enough.
++        self.pass_time(5)
+         while self.bytes_available():
+             self.iterate()
+         # TODO Test whether we got a firmware name and version, otherwise there 
+FlushInput.diff
 # Placed by Bitbucket
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.