← index #12037Issue #11253
Related · medium · value 0.877
QUERY · ISSUE

Data loss in string transfer through sys.stdout.write

openby pchalaopened 2023-07-18updated 2024-10-06
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

closedby pchalaopened 2023-04-13updated 2023-04-25
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))

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied