Source

pyFirmata_nickraptis_mq / WaitAndInit.diff

Full commit
# HG changeset patch
# Parent b87536297995a9e7f51b475f47c92bdf473aa94d
Wait and iterate over initial firmata messages

Specifically get Firmware and Port Init messages
when openning a Board, instead of depending to the
user to set up an iterator or loop.

diff -r b87536297995 -r cc2fbead01b6 pyfirmata/pyfirmata.py
--- a/pyfirmata/pyfirmata.py	Mon May 16 22:56:53 2011 +0300
+++ b/pyfirmata/pyfirmata.py	Mon May 16 23:01:17 2011 +0300
@@ -67,14 +67,18 @@
     
     def __init__(self, port, layout, baudrate=57600, name=None):
         self.sp = serial.Serial(port, baudrate)
-        # Allow 2 secs for Arduino's auto-reset to happen
-        # TODO Is this still necessary?
-        self.pass_time(2)
+        # 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.
+        self.pass_time(5)
         self.name = name
         if not self.name:
             self.name = port
         self.setup_layout(layout)
-        # TODO Test if we get a firmware name and version, otherwise there 
+        # Iterate over the first messages to get firmware data
+        while self.available():
+            self.iterate()
+        # TODO Test whether we got a firmware name and version, otherwise there 
         # probably isn't any Firmata installed
         
     def __str__(self):