logo

串口接收32的发过来的信息,可以运行,但运行十几秒钟就会出现UincodeError 错误,

2021-08-13 16:28
4
oyxs
while(True):
    #uart.write("11500\r\n")
    t=millis()
    if uart.any():
        led1.toggle()
        led1.on()
        #s1.Servo(45)
        a=uart.readline().decode()
        print(a)
        if a=="a":
            while(x<=t+10000 and ok==1):
                x=millis()
                #print("x:",x)
                img = sensor.snapshot()
                yyys=img.find_blobs([(63, 27, 78, 36, -6, 76),(43, 82, 1, -19, 19, 64)],x_stride=20, y_stride=10, pixels_threshold=1500, area_threshold=1500, merge=True)
                if yyys:
                       yyy=find_max(yyys)
                       img.draw_rectangle(yyy.rect())
                       img.draw_cross(yyy.cx(),yyy.cy())
                       print(str(yyy.cx()),str(yyy.pixels()))
                       uart.write(str(yyy.cx())+","+str(yyy.cy())+"\r\n")
                       led1.off()
                       time.sleep(1)
                       led2.toggle()
                       led2.on()

        else:
            print("不是A")
    else:
        print("未接收")
45bb4f99-c097-42d8-8008-f74e822f4e9a.png
4
oyxs

系统显示是a=uart.readline().decode(),这一步有问题

2021-08-13 21:01
I
网红小智智 星瞳科技

说明接受的不是unicode编码的,不是字符串,所以不能decode。

具体你发送的是什么,先打印出readline的结果看看。

2021-08-14 00:04
4
oyxs

@kidswong999 在 [串口接收32的发过来的信息,可以运行,但运行十几秒钟就会出现UincodeError 错误,](/post/22424) 中说:

> 明接受的不是

确实,stm32程序里写的是发送一个a 但是把发送函数放在了while循环里。有时候接收的信息是aaaaaaaaaaaaaaaaaaaaa

2021-08-16 16:34
I
网红小智智 星瞳科技

如果你在OpenMV里readline的话,那么stm32要发送`a\r\n`,而不是`a`

2021-08-18 21:00
4
oyxs

@kidswong999 明白了·谢谢