QUERY · ISSUE
Data loss in string transfer through sys.stdout.write
bugport-rp2
Env: MicroPython v1.20.0 on 2023-04-26; Raspberry Pi Pico with RP2040
I have noticed constant data loss when transfer string objects with help of sys.stdout.write() method.
MCU code:
import sys
BUF_SIZE = 10000
while True:
sys.stdin.readline()
line = bytes(BUF_SIZE).hex() + '\n'
sys.stdout.write(line)
PC code:
import serial
connection = serial.Serial('COM6', timeout=3)
for i in range(1000):
connection.write(b'\n')
res = connection.readline()
print(i, len(res))
If BUF_SIZE set to 8000 everything will work fine.
In case of sending bytes:
import sys
BUF_SIZE = 40000
while True:
sys.stdin.readline()
line = bytes(BUF_SIZE)
sys.stdout.write(line)
transfer is ok even for 40000 bytes.
CANDIDATE · ISSUE
On RP2 sys.stdin.read(64) and sys.stdin.readline() do not work if we have multiple of 64 bytes in buffer
port-rp2
MicroPython v1.19.1-994-ga4672149b on 2023-03-29; Raspberry Pi Pico with RP2040
Pico code:
import sys
while True:
line = sys.stdin.read(64)
print(len(line))