Skip to content

Commit

Permalink
Added optional wait parameter for slower bootloaders.
Browse files Browse the repository at this point in the history
Fixes #1.
  • Loading branch information
jfjlaros committed Jan 5, 2019
1 parent 9270522 commit a0cab04
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
13 changes: 9 additions & 4 deletions simple_rpc/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,31 @@ def _describe_method(method):
return description


def rpc_list(handle, device, baudrate):
def rpc_list(handle, device, baudrate, wait):
"""List the device methods.
:arg stream handle: Output handle.
:arg str device: Serial device.
:arg int baudrate: Baud rate.
:arg int wait: Time in seconds before communication starts.
"""
interface = Interface(device, baudrate)
interface = Interface(device, baudrate, wait)

for method in interface.methods.values():
handle.write(_describe_method(method) + '\n\n\n')


def rpc_call(handle, device, baudrate, name, args):
def rpc_call(handle, device, baudrate, wait, name, args):
"""Execute a method.
:arg stream handle: Output handle.
:arg str device: Serial device.
:arg int baudrate: Baud rate.
:arg int wait: Time in seconds before communication starts.
:arg str name: Method name.
:arg list args: Method parameters.
"""
interface = Interface(device, baudrate)
interface = Interface(device, baudrate, wait)

result = interface.call_method(name, *args)
if result != None:
Expand All @@ -76,6 +78,9 @@ def main():
common_parser.add_argument(
'-b', dest='baudrate', type=int, default=9600,
help='baud rate (%(type)s default=%(default)s)')
common_parser.add_argument(
'-w', dest='wait', type=int, default=1,
help='time before communication starts (%(type)s default=%(default)s)')
common_parser.add_argument(
'-o', dest='handle', metavar='OUTPUT', type=FileType('w'),
default=stdout, help='output file')
Expand Down
5 changes: 3 additions & 2 deletions simple_rpc/simple_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,18 @@ def _parse_line(index, line):


class Interface(object):
def __init__(self, device, baudrate=9600):
def __init__(self, device, baudrate=9600, wait=1):
"""Initialise the class.
:arg str device: Serial device name.
:arg int baudrate: Baud rate.
:arg int wait: Time in seconds before communication starts.
"""
try:
self._connection = Serial(device, baudrate)
except SerialException as error:
raise IOError(error.strerror.split(':')[0])
sleep(1)
sleep(wait)

self.methods = self._get_methods()
for method in self.methods.values():
Expand Down

0 comments on commit a0cab04

Please sign in to comment.