Exemplo n.º 1
0
    def read(self, length, timeout=None):
        if timeout != self.ser.timeout:
            try:
                self.ser.timeout = timeout
            except ValueError as e:
                logging.error("Error setting UART read timeout. Continuing.")

        try:
            value = self.ser.read(length)
        except Exception as e:
            logging.error("UART Error:" + str(e))
            self.close()
            raise

        if len(value) != length:
            raise Exceptions.SnifferTimeout("UART read timeout (" +
                                            str(self.ser.timeout) +
                                            " seconds).")

        if self.useByteQueue:
            self.byteQueue.extend(stringToList(value))
        return value
Exemplo n.º 2
0
 def getSerialByte(self, timeout=None):
     serialByte = self.uart.readByte(timeout)
     if len(serialByte) != 1:
         raise Exceptions.SnifferTimeout("Byte read timed out.")
     return ord(serialByte)