1. Tino de Bruijn
  2. pyFirmata

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
  • Branches default

Comments (0)

Files changed (2)

File pyfirmata/pyfirmata.py

View file
  • Ignore whitespace
             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.

File pyfirmata/util.py

View file
  • Ignore whitespace
     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: