Commits

Tino de Bruijn committed dfcaa00

Added function to query Board for available bytes.

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

Thanks to nickraptis

  • Participants
  • Parent commits e8a8f7c

Comments (0)

Files changed (2)

pyfirmata/pyfirmata.py

             self.sp.write(byte)
         self.sp.write(chr(END_SYSEX))
         
+    def bytes_available(self):
+        return self.sp.inWaiting()
+
     def iterate(self):
         """ 
         Reads and handles data from the microcontroller over the serial port.

pyfirmata/util.py

     def run(self):
         while 1:
             try:
-                while self.board.iterate():
+                while self.board.bytes_available():
                     self.board.iterate()
                 time.sleep(0.001)
             except (AttributeError, serial.SerialException, OSError), e: