summaryrefslogtreecommitdiffstatshomepage
path: root/tools
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-11-30 21:30:53 +0000
committerDamien George <damien.p.george@gmail.com>2014-11-30 21:30:53 +0000
commit17c5ce372748a646d973e098bf1244fba98e3bfc (patch)
tree395e3d0257111cace8eaf893911e3d069df6c629 /tools
parent1960475ed7e190bcf537f8f7714a543b7513e2d5 (diff)
downloadmicropython-17c5ce372748a646d973e098bf1244fba98e3bfc.tar.gz
micropython-17c5ce372748a646d973e098bf1244fba98e3bfc.zip
tools: Make pyboard.py have infinite timeout when running script.
This makes pyboard.py much more useful for long running scripts. When running a script via pyboard.py, it now waits until the script finishes, with no timeout. CTRL-C can be used to break out of the waiting if needed.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/pyboard.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/tools/pyboard.py b/tools/pyboard.py
index d5a01720b7..036f6056cd 100755
--- a/tools/pyboard.py
+++ b/tools/pyboard.py
@@ -60,7 +60,7 @@ class Pyboard:
timeout_count = 0
else:
timeout_count += 1
- if timeout_count >= 10 * timeout:
+ if timeout is not None and timeout_count >= 10 * timeout:
break
time.sleep(0.1)
return data
@@ -81,15 +81,15 @@ class Pyboard:
def exit_raw_repl(self):
self.serial.write(b'\r\x02') # ctrl-B: enter friendly REPL
- def follow(self, data_consumer=False):
+ def follow(self, timeout, data_consumer=None):
# wait for normal output
- data = self.read_until(1, b'\x04', data_consumer=data_consumer)
+ data = self.read_until(1, b'\x04', timeout=timeout, data_consumer=data_consumer)
if not data.endswith(b'\x04'):
raise PyboardError('timeout waiting for first EOF reception')
data = data[:-1]
# wait for error output
- data_err = self.read_until(2, b'\x04>')
+ data_err = self.read_until(2, b'\x04>', timeout=timeout)
if not data_err.endswith(b'\x04>'):
raise PyboardError('timeout waiting for second EOF reception')
data_err = data_err[:-2]
@@ -97,7 +97,7 @@ class Pyboard:
# return normal and error output
return data, data_err
- def exec_raw(self, command, data_consumer=False):
+ def exec_raw(self, command, timeout=10, data_consumer=None):
if isinstance(command, bytes):
command_bytes = command
else:
@@ -114,7 +114,7 @@ class Pyboard:
if data != b'OK':
raise PyboardError('could not exec command')
- return self.follow(data_consumer)
+ return self.follow(timeout, data_consumer)
def eval(self, expression):
ret = self.exec('print({})'.format(expression))
@@ -214,7 +214,7 @@ def main():
if len(args.files) == 0:
try:
pyb = Pyboard(args.device)
- ret, ret_err = pyb.follow(data_consumer=lambda d:print(str(d, encoding='ascii'), end=''))
+ ret, ret_err = pyb.follow(timeout=None, data_consumer=lambda d:print(str(d, encoding='ascii'), end=''))
pyb.close()
except PyboardError as er:
print(er)
@@ -231,7 +231,7 @@ def main():
pyb.enter_raw_repl()
with open(filename) as f:
pyfile = f.read()
- ret, ret_err = pyb.exec_raw(pyfile, data_consumer=lambda d:print(str(d, encoding='ascii'), end=''))
+ ret, ret_err = pyb.exec_raw(pyfile, timeout=None, data_consumer=lambda d:print(str(d, encoding='ascii'), end=''))
pyb.exit_raw_repl()
pyb.close()
except PyboardError as er: