logo

串口通讯接收数据错误,只能接收到65字节左右?

2020-05-19 10:33
M
wgqv

为什么不能连续两次进行读取数据,连续两次读取及只能接收65字节。

如果只读取一次就是正常的,但是我的程序需要读一次发一次再读一次发一次这样。

import time
from pyb import UART
uart = UART(3,115200)
uart.init(115200,bits=8,parity=None,stop=1)
while True:
    if uart.any():
        a=uart.read().decode()
        print(a)
    time.sleep(1000)
    if uart.any():
        a=uart.read().decode()
        print(a)

发送的数据是1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950

接收到的只有12345678910111213141516171819202122232425262728293031323334353637

应该如何解决?

2020-05-19 17:01
I
网红小智智 星瞳科技

加一个timeout_char参数看一下。

uart.init(115200,bits=8,parity=None,stop=1, timeout_char=1000)

2020-05-20 18:17
M
wgqv

@kidswong999 已试过,没用

2020-05-21 18:25
I
网红小智智 星瞳科技

https://docs.singtown.com/micropython/zh/latest/openmvcam/library/pyb.UART.html

UART.init函数里面,read_buf_len默认是64,改大参数就行。