Hello,
could you assist to get this timeout change for retries in Xbee.py?
Regards,
Paulus
-------- Origineel bericht --------
Onderwerp: Re: add timeout to xbee.wait_read_frame Datum: Mon, 4 Aug 2014 13:33:51 -0700 Van: Amit Snyderman <amitsn...@gmail.com> Aan: paul knijn <paul...@gmail.com>
Paulus, this page lists their full email addresses: https://pypi.python.org/pypi/XBee
Paul Malmsten <pmal...@gmail.com>Greg Rapp <gdr...@gmail.com>Brian <bla...@bravo5.org>On Monday, August 4, 2014 at 1:05 PM, paul knijn wrote:
Hi Amit,
could you forward this email. The address I got does not work : pmalms...@gmail.com
Cheers,
Paulus
Amit Snyderman schreef op 4-8-2014 4:24:
Hey Paul, I’m actually not the maintainer of this project anymore. I’d recommend sending a patch (unfortunately they’re not on GitHub or this would be a perfect pull-request opportunity) to the current maintainers. You can find their info @ https://code.google.com/p/python-xbee/
On Sunday, August 3, 2014 at 12:24 PM, paul knijn wrote:
Hi,
im having problems that my programs are getting stuck on packet loss due to the infinite read loop in wait_read_frame().
Do you think you could add a timeout? I already implemented this, I just would like a versioned installer. If timeout expires I want to do a retry on the read...
Cheers,
Paulus
def _wait_for_frame(self, timeout):
"""
_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.
"""
frame = APIFrame(escaped=self._escaped)
t0 = time.time()
while (time.time()-t0 < timeout):
if self._callback and not self._thread_continue:
raise ThreadQuitException
if self.serial.inWaiting() == 0:
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)
print "time-out while trying to read data"