diff options
author | Damien George <damien.p.george@gmail.com> | 2015-06-15 23:28:04 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-06-15 23:28:04 +0100 |
commit | d59ca4efdbcf572b9f77b8e5b045c939181a3089 (patch) | |
tree | f98241a876dd667040c24ea373a3293fa369c145 /tools/pyboard.py | |
parent | 3ce212e0a67424c4c89c273e7509be84dc30a172 (diff) | |
download | micropython-d59ca4efdbcf572b9f77b8e5b045c939181a3089.tar.gz micropython-d59ca4efdbcf572b9f77b8e5b045c939181a3089.zip |
tools/pyboard.py: Change logic for when raw ">" prompt is parsed.
In raw REPL ">" indicates the prompt. We originally read this character
upon entering the raw REPL, and after reading the last bit of the
output. This patch changes the logic so the ">" is read only just
before trying to send the next command. To make this work (and as an
added feature) the input buffer is now flushed upon entering raw REPL.
The main reason for this change is so that pyboard.py recognises the EOF
when sys.exit() is called on the pyboard. Ie, if you run pyboard.py
with a script that calls sys.exit(), then pyboard.py will exit after
the sys.exit() is called.
Diffstat (limited to 'tools/pyboard.py')
-rwxr-xr-x | tools/pyboard.py | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/tools/pyboard.py b/tools/pyboard.py index 27665d9055..162a15024c 100755 --- a/tools/pyboard.py +++ b/tools/pyboard.py @@ -71,14 +71,22 @@ class Pyboard: def enter_raw_repl(self): self.serial.write(b'\r\x03\x03') # ctrl-C twice: interrupt any running program + + # flush input (without relying on serial.flushInput()) + n = self.serial.inWaiting() + while n > 0: + self.serial.read(n) + n = self.serial.inWaiting() + self.serial.write(b'\r\x01') # ctrl-A: enter raw REPL data = self.read_until(1, b'to exit\r\n>') if not data.endswith(b'raw REPL; CTRL-B to exit\r\n>'): print(data) raise PyboardError('could not enter raw repl') + self.serial.write(b'\x04') # ctrl-D: soft reset - data = self.read_until(1, b'to exit\r\n>') - if not data.endswith(b'raw REPL; CTRL-B to exit\r\n>'): + data = self.read_until(1, b'to exit\r\n') + if not data.endswith(b'raw REPL; CTRL-B to exit\r\n'): print(data) raise PyboardError('could not enter raw repl') @@ -93,8 +101,8 @@ class Pyboard: data = data[:-1] # wait for error output - data_err = self.read_until(2, b'\x04>', timeout=timeout) - if not data_err.endswith(b'\x04>'): + data_err = self.read_until(1, b'\x04', timeout=timeout) + if not data_err.endswith(b'\x04'): raise PyboardError('timeout waiting for second EOF reception') data_err = data_err[:-2] @@ -107,6 +115,11 @@ class Pyboard: else: command_bytes = bytes(command, encoding='utf8') + # check we have a prompt + data = self.read_until(1, b'>') + if not data.endswith(b'>'): + raise PyboardError('could not enter raw repl') + # write command for i in range(0, len(command_bytes), 256): self.serial.write(command_bytes[i:min(i + 256, len(command_bytes))]) |