代码出现类型错误?如何解决?
-
import sensor, image, time ,struct,json
from pyb import UART
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(100)
sensor.set_auto_gain(False)
sensor.set_auto_whitebal(False)
clock=time.clock()uart = UART(3, 15200)
threshold=[(81, 23, 89, 43, 4, 52),(70, 27, -71, -18, -21, 41), (58, 29, 3, 51, -82, -17)] #红色 绿色 蓝色
red_threshold=[(81, 23, 89, 43, 4, 52)]
green_threshold=[(70, 27, -71, -18, -21, 41)]
blue_threshold=[(58, 29, 3, 51, -82, -17)]def red():
for blob in img.find_blobs(red_threshold,pixels_threshold=400,area_threshold=400):
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(),blob.cy())
datahex0 = struct.pack("B", 255)
datahex1 = struct.pack("B", blob.code())
datahex2 = struct.pack("B", blob.cx())
datahex3 = struct.pack("B", blob.cy())
dataHexAll = datahex0 +datahex1 +datahex2 +datahex3
uart.write(dataHexAll)
def green():
for blob in img.find_blobs(green_threshold,pixels_threshold=400,area_threshold=400):
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(),blob.cy())
datahex0 = struct.pack("B", 255)
datahex1 = struct.pack("B", blob.code())
datahex2 = struct.pack("B", blob.cx())
datahex3 = struct.pack("B", blob.cy())
dataHexAll = datahex0 +datahex1 +datahex2 +datahex3
uart.write(dataHexAll)
def blue():
for blob in img.find_blobs(blue_threshold,pixels_threshold=400,area_threshold=400):
img.draw_rectangle(blob.rect())
img.draw_cross(blob.cx(),blob.cy())
datahex0 = struct.pack("B", 255)
datahex1 = struct.pack("B", blob.code())
datahex2 = struct.pack("B", blob.cx())
datahex3 = struct.pack("B", blob.cy())
dataHexAll = datahex0 +datahex1 +datahex2 +datahex3
uart.write(dataHexAll)global Flag
Flag=0while(True):
clock.tick()
img = sensor.snapshot()
for code in img.find_qrcodes():
img.draw_rectangle(code.rect(), color = (0, 0, 255))
print(code[4][0],code[4][1],code[4][2]) #返回二维码所载荷的有效字符
datahex0 = struct.pack("B", 255)
datahex1 = struct.pack("B", code[4])
shuchu=datahex0+datahex1
uart.write(shuchu)
-
你的代码不应该这么写。
你可以直接uart.write(code.payload())
-
我试过了,这样的话还是不行没有接收到
-
不会收不到。
你应该先使用串口调试扩展板和软件调试。
-
我用的是官网下载的调试软件,前面用struct进行数据压缩可以发送接收,如果这样老是接收不到
-
如果直接uart.write(code.payload())接收到的是乱码,不对
-
发送的是字符串,接受也要用字符串显示。
https://singtown.com/learn/50235/
-
那怎样才能吧code。paylload()转换成数字去发送?
-
二维码里面的payload本来就是字符串。
-
我应该怎样能把字符串转换成其他形式发送?
-
因为我在接收的时候接收到的打包一起的一个数组
-
@gtxp 楼主,解决没