jfjlaros / simpleRPC

Simple RPC implementation for Arduino.
MIT License
50 stars 17 forks source link

Enable a timeout after opening a serial connection #1

Closed apfeiffe closed 5 years ago

apfeiffe commented 5 years ago

Is your feature request related to a problem? Please describe.

Depending on the connection speed and/or hardware of the serial port the opening of the interface may fail and you have to CTRL-C'it ...

Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from simple_rpc import Interface
>>> interface = Interface('/dev/ttyUSB0',9600)
^CTraceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/xxx/Downloads/simpleRPC/simple_rpc/simple_rpc.py", line 133, in __init__

Describe the solution you'd like

Enable another parameter to increase the timeout to prevent a conflict with the bootloader of the Arduino. Probably like this in file simple_rpc/simple_rpc.py:

class Interface(object):
    def __init__(self, device, baudrate=9600, towait=1):
        """Initialise the class.

        :arg str device: Serial device name.
        :arg int baudrate: Baud rate.
        :arg int towait: Wait after opening serial interface.
        """
        try:
            self._connection = Serial(device, baudrate)
        except SerialException as error:
            raise IOError(error.strerror.split(':')[0])
        sleep(towait)

Thanks.

jfjlaros commented 5 years ago

Thank you for this suggestion, I will implement this.