def listen(self):
eol = b'\n'
eol_len = len(eol)
line = bytearray()
while True:
try:
c = self.serial.read(1)
if c:
line += c
if line[-eol_len:] == eol:
print(line)
sample = struct.unpack('<' + 'h'*(len(line[:-eol_len])//2), line[:-eol_len])
print(sample)
self.emitter.emit(sample[-2:])
line = bytearray()
except SerialException:
return
except AttributeError:
return
except struct.error:
continue
评论列表
文章目录