I added similar blocks and delays to Thonny IDE (256-byte blocks and 0.01 second delays between blocks, as in pyboard.py). Still, a Thonny user was able to receive a SyntaxError with code that looks fine and works on my machine (https://github.com/thonny/thonny/issues/1336). From posts discussing rshell, I learned that sometimes it's useful to use even smaller blocks when writing to the device.
In order to learn more about this, I made a test-program using PySerial, which is supposed to tell me whether a block of given size goes through intact or not:
Code: Select all
import serial
PORT = "/dev/ttyACM0"
LENGTH_OF_STRING_LITERAL = 1200
# The output of following code tells me whether the code was received intact or not
code = """
s = "%s"
print()
print(len(s), set(s))
""" % ("*" * LENGTH_OF_STRING_LITERAL)
s = serial.Serial(PORT, 115200)
print("Interrupting and requesting raw promt...")
s.write(b"\x03")
s.write(b"\x03")
s.write(b"\x01")
print(s.read_until(b"exit\r\n>"))
print("Got raw prompt. Executing code...")
for i in range(20):
s.write(code.encode("UTF-8"))
s.flush()
s.write(b"\x04")
print(s.read_until(b"OK"))
# wait until completion
print(s.read_until(b">"))
while True:
print(s.read(1).decode(), end="")
The only way I could make the device receive broken code, was by omitting the line marked with "# wait until completion" -- it looks like I was able overwhelm the device only when it was busy executing some code.
My questions:
* Can you see any mistakes in my experiment?
* Can you suggest another experiment or another device for reproducing idle raw-REPL receiving broken input?
* Where are these input buffers that need chunked input and delays between chunks? On the device? Inside USB driver?
* Would you recommend using paste-mode for inputting long commands to the REPL? It looks like the echo provided by this mode could be used as flow control (by reading the echo of previous line before writing next line). Do you see any problems with this?