code: def _wait_for_frame(self, timeout=None):
          
          frame = APIFrame(escaped=self._escaped)
  
          deadline = 0
          if timeout is not None and timeout > 0:
              deadline = time.time() + timeout
  
          while True:
                  if self._callback and not self._thread_continue:
                      raise ThreadQuitException
  
                  if self.serial.inWaiting() == 0:
                      if deadline and time.time() > deadline:
                          raise _TimeoutException
                      time.sleep(.01)
                      continue
  
                  byte = self.serial.read()
  
                  if byte != APIFrame.START_BYTE:
                      continue
  
                  # Save all following bytes, if they are not empty
                  if len(byte) == 1:
                      frame.fill(byte)
  
                  while(frame.remaining_bytes() > 0):
                      byte = self.serial.read()
  
                      if len(byte) == 1:
                          frame.fill(byte)
  
                  try:
                      # Try to parse and return result
                      frame.parse()
  
                      # Ignore empty frames
                      if len(frame.data) == 0:
                          frame = APIFrame()
                          continue
  
                      return frame
                  except ValueError:
                      # Bad frame, so restart
                      frame = APIFrame(escaped=self._escaped)
docs: _wait_for_frame: None -> binary data
  
          _wait_for_frame will read from the serial port until a valid
          API frame arrives. It will then return the binary data
          contained within the frame.
  
          If this method is called as a separate thread
          and self.thread_continue is set to False, the thread will
          exit by raising a ThreadQuitException.