def read(self, timeout):
if self.tty is not None:
self.tty.timeout = max(timeout/1E3, 0.05)
frame = bytearray(self.tty.read(6))
if frame is None or len(frame) == 0:
raise IOError(errno.ETIMEDOUT, os.strerror(errno.ETIMEDOUT))
if frame.startswith(b"\x00\x00\xff\x00\xff\x00"):
log.log(logging.DEBUG-1, "<<< %s", str(frame).encode("hex"))
return frame
LEN = frame[3]
if LEN == 0xFF:
frame += self.tty.read(3)
LEN = frame[5] << 8 | frame[6]
frame += self.tty.read(LEN + 1)
log.log(logging.DEBUG-1, "<<< %s", hexlify(frame))
return frame
评论列表
文章目录