def poll(self, bufsize=1024):
""" Returns the next received packet as a tuple (command, payload)
If there are no packets pending, returns None
"""
# Attempt to load data from USB and push it into the incoming buffer
while not self.incoming:
try:
raw = self._read(bufsize)
except usb.core.USBError as e:
# The only acceptable USB errors are timeout errors
# (when the device hasn't sent us any new data)
if e.errno != errno.ETIMEDOUT:
raise e
break
else:
self._process_raw(raw)
# Return the oldest packet or None
return self.incoming.pop(0) if self.incoming else None
评论列表
文章目录