sci-bots / base-node-rpc

Base classes for Arduino RPC node/device
0 stars 2 forks source link

bug(connect): TimeoutError on connection attempt #21

Closed cfobel closed 5 years ago

cfobel commented 5 years ago

For example:

In [1]: import logging; logging.basicConfig(level=logging.DEBUG)

In [2]: import base_node_rpc as bnr; proxy = bnr.SerialProxy(port='COM16')
DEBUG:trollius:Using selector: SelectSelector
DEBUG:base_node_rpc.async:`ProactorEventLoop` required, not `<class 'trollius.windows_events._WindowsSelectorEventLoop'>`loop in background thread.
DEBUG:base_node_rpc.async:Execute new loop in background thread.
DEBUG:trollius:Using proactor: IocpProactor
DEBUG:base_node_rpc._async_py27.read_packet:error communicating with port `COM16`
Traceback (most recent call last):
  File "base_node_rpc\_async_py27.py", line 42, in read_packet
    character = yield asyncio.From(serial_.read(8 << 10))
CancelledError
---------------------------------------------------------------------------
TimeoutError                              Traceback (most recent call last)
<ipython-input-2-aaa217852922> in <module>()
----> 1 import base_node_rpc as bnr; proxy = bnr.SerialProxy(port='COM16')

C:\Users\chris\Documents\GitHub\dropbot.py\.dropbot-recipes\_source\base-node-rpc\base_node_rpc\proxy.pyc in __init__(self, **kwargs)
    275         self.device_verified = threading.Event()
    276
--> 277         self._connect(port=port, baudrate=baudrate)
    278
    279     @property

C:\Users\chris\Documents\GitHub\dropbot.py\.dropbot-recipes\_source\base-node-rpc\base_node_rpc\proxy.pyc in _connect(self, port, baudrate, settling_time_s, retry_count, ignore)
    439         for port_i in ports:
    440             # Read device ID.
--> 441             device_id = read_device_id(port=port_i, timeout=settling_time_s)
    442
    443             if device_id is not None and device_name is not None:

C:\Users\chris\Documents\GitHub\dropbot.py\.dropbot-recipes\_source\base-node-rpc\base_node_rpc\async.py in wrapped(*args, **kwargs)
     84             finished.wait()
     85             if finished.error is not None:
---> 86                 raise finished.error
     87             return finished.result
     88

TimeoutError:
cfobel commented 5 years ago

This issue was introduced by da06c61fa55415b91e70c7b6d062e58033c601e9.

Prior to da06c61fa55415b91e70c7b6d062e58033c601e9, the base_node_rpc.async.read_device_id() function propagated the timeout keyword argument to the _read_device_id(..., timeout=...) coroutine call.

In da06c61fa55415b91e70c7b6d062e58033c601e9, the timeout argument of the base_node_rpc.async.read_device_id() function is instead passed to the top-level asyncio.wait(..., timeout=...) call directly (which wraps the calls _read_device_id() coroutine). The default timeout of 0 causes the wrapped _read_device_id() coroutine call to exit before having a chance to read a response.

Proposed fix

Set the default settling_time_s timeout value to 25 ms in SerialProxyMixin.___init__(). This will ensure backwards compatibility with base-node-rpc<0.51.1.