openmv串口接收数据串行的问题
-
if uart.any() : a = uart.readline().decode()
串口接收使用这样的代码
服务器发送消息 连续发送的状态下 串口接收的数据会出现串行的情况 除了在服务器上做延时操作 openmv上的代码需要修改吗?
下面是服务器连续发送 www.singtown.com 串口接收的情况
-
全部的代码是什么?
我看看你的初始化的代码对不对。
-
import sensor, image, time ,tv from pyb import UART import hashlib from pyb import Pin, Timer sensor.reset() sensor.set_pixformat(sensor.GRAYSCALE) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time = 2000) sensor.set_auto_gain(False) # must turn this off to prevent image washout... clock = time.clock() uart = UART(3, 19200) tv.init() # 初始化tv # 50kHz pin6 timer2 channel1 #light = Timer(2, freq=18000).channel(1, Timer.PWM, pin=Pin("P6")) #light.pulse_width_percent(100) # adjust light 0~100 #crc16 modbus def crc16(x, invert): a = 0xffff b = 0xa001 #x = x.encode(encoding='UTF-8',errors='strict') for byte in x: print(ord(byte)) a ^= ord(byte) for i in range(8): last = a % 2 a >>= 1 if last == 1: a ^= b print(a) s = hex(a) return s[4:6]+s[2:4] if invert == True else s[2:4]+s[4:6] while(True): clock.tick() img = sensor.snapshot() #使用无畸变镜头 #img.lens_corr(1.8) # strength of 1.8 is good for the 2.8mm lens. for code in img.find_qrcodes(): img.draw_rectangle(code.rect(), color = (255, 0, 0)) #print(code.payload()) #fmd5 = hashlib.md5(code.payload()) #fmd5 = hashlib.sha256(code.payload()).digest() #data2 =crc16(code.payload(),False) #print(fmd5) #print(data2) if code.payload() is not None : uart.write(code.payload()+ "\r") tv.display(img) if uart.any() : a = uart.read().decode() print(a) # print(clock.fps())
服务器收到串口信息 然后转发回串口的是 www.singtown.com\r
-
a = uart.readline().decode() 改为 a = uart.read().decode() 是这个问题吗
-
uart = UART(3, 19200)改为uart = UART(3, 19200,timeout=1000)
-
@kidswong999 谢谢