def iterate(self):
        """
        Reads and handles data from the microcontroller over the serial port.
        This method should be called in a main loop or in an :class:`Iterator`
        instance to keep this boards pin values up to date.
        """
        byte = self.sp.read()
        if not byte:
            return
        data = ord(byte)
        received_data = []
        handler = None
        if data < START_SYSEX:
            # These commands can have 'channel data' like a pin nummber appended.
            try:
                handler = self._command_handlers[data & 0xF0]
            except KeyError:
                return
            received_data.append(data & 0x0F)
            while len(received_data) < handler.bytes_needed:
                received_data.append(ord(self.sp.read()))
        elif data == START_SYSEX:
            data = ord(self.sp.read())
            handler = self._command_handlers.get(data)
            if not handler:
                return
            data = ord(self.sp.read())
            while data != END_SYSEX:
                received_data.append(data)
                data = ord(self.sp.read())
        else:
            try:
                handler = self._command_handlers[data]
            except KeyError:
                return
            while len(received_data) < handler.bytes_needed:
                received_data.append(ord(self.sp.read()))
        # Handle the data
        try:
            handler(*received_data)
        except ValueError:
            pass
def iterate ( self ) : byte = self . sp . read ( ) if not byte : return data = ord ( byte ) received_data = [ ] handler = None if data < START_SYSEX : try : handler = self . _command_handlers [ data & 0xF0 ] except KeyError : return received_data . append ( data & 0x0F ) while len ( received_data ) < handler . bytes_needed : received_data . append ( ord ( self . sp . read ( ) ) ) elif data == START_SYSEX : data = ord ( self . sp . read ( ) ) handler = self . _command_handlers . get ( data ) if not handler : return data = ord ( self . sp . read ( ) ) while data != END_SYSEX : received_data . append ( data ) data = ord ( self . sp . read ( ) ) else : try : handler = self . _command_handlers [ data ] except KeyError : return while len ( received_data ) < handler . bytes_needed : received_data . append ( ord ( self . sp . read ( ) ) ) try : handler ( * received_data ) except ValueError : pass
Reads and handles data from the microcontroller over the serial port.
        This method should be called in a main loop or in an :class:`Iterator`
        instance to keep this boards pin values up to date.