因?yàn)檎搲锱加斜г勾谠诟卟ㄌ芈氏抡`碼率很高的問(wèn)題,我今天做了一次測(cè)試:
用WCH LinkE與CH340相連,程序如下:
from serial import Serial
from random import randint, randbytes
from time import sleep
#BAUD = 921600
BAUD = 115200*4
ser1 = Serial('/dev/ttyUSB0', BAUD, timeout=1)
ser2 = Serial('/dev/ttyACM0', BAUD, timeout=1)
err_1_2 = 0
err_2_1 = 0
for i in range(10000):
??? print('Round', i)
??? l = randint(1, 300)
??? tx_buf = randbytes(l)
??? ser1.write(tx_buf)
??? ser1.flush()
??? rx_buf1 = ser2.read(l)
??? if tx_buf != rx_buf1:
??????? err_1_2+=1
??????? print(f'Error comminication 1->2 {err_1_2}, tlen={l}, rlen={len(rx_buf1)}')
??????? sleep(1)
??????? ser2.reset_input_buffer()
??? ser2.write(tx_buf)
??? ser2.flush()
??? rx_buf2 = ser1.read(l)
??? if tx_buf != rx_buf2:
??????? err_2_1+=1
??????? print(f'Error comminication 2->1 {err_2_1}, tlen={l}, rlen={len(rx_buf1)}')
??????? sleep(1)
??????? ser1.reset_input_buffer()
print(f'Total: err_1_2 {err_1_2}, err_2_1 {err_2_1}')
經(jīng)測(cè)試,在921600bps下會(huì)有100次里面1、2次的錯(cuò)誤,在460800、115200下10000次均無(wú)錯(cuò)誤。
當(dāng)然,我只是用一個(gè)WCH LinkE,不一定具有代表性,但是可以作為一個(gè)測(cè)試思路分享給各位。