<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<br>
<div class="moz-cite-prefix">El 27/03/16 a las 17:42, Dan Smith via
chirp_devel escribió:<br>
</div>
<blockquote cite="mid:56F853B1.4060105@danplanet.com" type="cite">
<blockquote type="cite" style="color: #000000;">
<pre wrap=""> def _rawrecv(radio, amount):
<span class="moz-txt-citetags">> </span>- """Raw read from the radio device, new approach, this time a byte at
<span class="moz-txt-citetags">> </span>- a time as the original driver, the receive data has to be atomic"""
<span class="moz-txt-citetags">> </span>+ """Raw read from the radio device, less intensive way"""
<span class="moz-txt-citetags">> </span>+
<span class="moz-txt-citetags">> </span> data = ""
<span class="moz-txt-citetags">> </span>
<span class="moz-txt-citetags">> </span> try:
<span class="moz-txt-citetags">> </span>- tdiff = 0
<span class="moz-txt-citetags">> </span>- start = time.time()
<span class="moz-txt-citetags">> </span>- maxtime = amount * 0.020
<span class="moz-txt-citetags">> </span>-
<span class="moz-txt-citetags">> </span>- while len(data) < amount and tdiff < maxtime:
<span class="moz-txt-citetags">> </span>- d = radio.pipe.read(1)
<span class="moz-txt-citetags">> </span>- if len(d) == 1:
<span class="moz-txt-citetags">> </span>- data += d
<span class="moz-txt-citetags">> </span>-
<span class="moz-txt-citetags">> </span>- # Delta time
<span class="moz-txt-citetags">> </span>- tdiff = time.time() - start
<span class="moz-txt-citetags">> </span>-
<span class="moz-txt-citetags">> </span>- # DEBUG
<span class="moz-txt-citetags">> </span>- if debug is True:
<span class="moz-txt-citetags">> </span>- LOG.debug("time diff %.04f maxtime %.04f, data: %d" %
<span class="moz-txt-citetags">> </span>- (tdiff, maxtime, len(data)))
<span class="moz-txt-citetags">> </span>+ # Getting the data with a dynamic timeout in the serial deppending on
<span class="moz-txt-citetags">> </span>+ # the amount of data we need
<span class="moz-txt-citetags">> </span>+ timeout = amount * 0.06
</pre>
</blockquote>
<pre wrap="">This really doesn't make any sense: the value of timeout doesn't need to
be greater if you're reading more data. The select() call that pyserial
is making doesn't know how much data you're asking for, it only reports
whether there is <b class="moz-txt-star"><span class="moz-txt-tag">*</span>any<span class="moz-txt-tag">*</span></b> data to be read from the descriptor. Further,
pyserial cuts down the timeout each time through the read loop, if it
has to go again. That means that if you're a little late on the first
read loop, your timeout is cut down even further in the second and
subsequent loops. Eventually that will end up cutting your timeout down
to very small (i.e. less than a byte interval) value, which will make
this unreliable. It might be good to review the implementation of
pyserial's read code:
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="https://github.com/pyserial/pyserial/blob/master/serial/serialposix.py#L470-L516">https://github.com/pyserial/pyserial/blob/master/serial/serialposix.py#L470-L516</a>
This is why you need to be processing incoming data into a queue if
you're having trouble with the timing bits. Relying on the timeouts like
you are is only going to work in lucky situations where you start your
read with enough timeout remaining to process the full block.
</pre>
</blockquote>
<br>
Good to know about the shrinking of the timeout by using this. I
will review the pyserial code now to better understand the issue.<br>
<br>
Can you point me to a example of the queue schema you mention here?<br>
<br>
73<br>
</body>
</html>