I use pyserial to send and receive a large data package to mcu board. Basically, mcu just receive and immediately transmit byte in ISR.
port = serial.Serial(
'COM12',
baudrate=921600,
timeout=0,
parity='N',
stopbits=1,
bytesize=8
)
msg1 = "z200f2000 126543f4 126543f4 126543f4 126543f4 126543f4 126543f4 126543f4 "
multi_msg = ""
for i in range(1000):
multi_msg = multi_msg + msg1 + str(i) + "\r\n"
port.reset_input_buffer()
port.reset_output_buffer()
ret1 = port.write(multi_msg)
print multi_msg
print ret1
ret2 = port.in_waiting
print ret2
rcv1 = port.read(port.in_waiting)
print repr(rcv1)
First problem is that the max number of bytes in input buffer (port.in_waiting) is 65536 bytes (64KB). It's the same if I use i.e. port.read(80000). Always read 64KB. Is this limitation for read()?
Also, it seems that my pyserial script lose some packages and not always (about 10% fails). If I use TeraTerm to send a large file everything is ok.
Thanks.
Solution was to put read() in separate thread to prevent buffer overruns.