Source

pyFirmata_nickraptis_mq / Available.diff

Full commit
# HG changeset patch
# Parent e421765cc80307de1e8fd2cd4693635ed1f17c1e
Function to query Board for available bytes.

Since Board.iterate() blocks, this is useful.
Also it's coherent with Arduino's Serial.available
However, it returns a more pythonic 0 when there's
nothing waiting instead of Arduino's C-like -1

diff -r e421765cc803 -r b87536297995 pyfirmata/pyfirmata.py
--- a/pyfirmata/pyfirmata.py	Mon May 16 22:48:46 2011 +0300
+++ b/pyfirmata/pyfirmata.py	Mon May 16 22:56:53 2011 +0300
@@ -218,6 +218,9 @@
             self.sp.write(byte)
         self.sp.write(chr(END_SYSEX))
         
+    def available(self):
+        return self.sp.inWaiting()
+
     def iterate(self):
         """ 
         Reads and handles data from the microcontroller over the serial port.
diff -r e421765cc803 -r b87536297995 pyfirmata/util.py
--- a/pyfirmata/util.py	Mon May 16 22:48:46 2011 +0300
+++ b/pyfirmata/util.py	Mon May 16 22:56:53 2011 +0300
@@ -96,7 +96,7 @@
     def run(self):
         while 1:
             try:
-                while self.board.iterate():
+                while self.board.available():
                     self.board.iterate()
                 time.sleep(0.001)
             except (AttributeError, serial.SerialException, OSError), e: