logo

条形码不能通过串口发送code.payload

2018-04-24 22:39
Q
周街

import sensor, image, time, math

from pyb import UART

import json

sensor.reset()

sensor.set_pixformat(sensor.GRAYSCALE)

sensor.set_framesize(sensor.VGA)

sensor.set_windowing((640, 80))

sensor.skip_frames(time = 2000)

sensor.set_auto_gain(False)

sensor.set_auto_whitebal(False)

clock = time.clock()

uart = UART(3,4800)

def barcode_name(code):

if(code.type() == image.EAN2):

return "EAN2"

if(code.type() == image.EAN5):

return "EAN5"

if(code.type() == image.EAN8):

return "EAN8"

if(code.type() == image.UPCE):

return "UPCE"

if(code.type() == image.ISBN10):

return "ISBN10"

if(code.type() == image.UPCA):

return "UPCA"

if(code.type() == image.EAN13):

return "EAN13"

if(code.type() == image.ISBN13):

return "ISBN13"

if(code.type() == image.I25):

return "I25"

if(code.type() == image.DATABAR):

return "DATABAR"

if(code.type() == image.DATABAR_EXP):

return "DATABAR_EXP"

if(code.type() == image.CODABAR):

return "CODABAR"

if(code.type() == image.CODE39):

return "CODE39"

if(code.type() == image.PDF417):

return "PDF417"

if(code.type() == image.CODE93):

return "CODE93"

if(code.type() == image.CODE128):

return "CODE128"

while(True):

clock.tick()

img = sensor.snapshot()

codes = img.find_barcodes()

for code in codes:

img.draw_rectangle(code.rect())

print_args = (barcode_name(code), code.payload(), (180 * code.rotation()) / math.pi, code.quality(), clock.fps())

print("Barcode %s, Payload \"%s\", rotation %f (degrees), quality %d, FPS %f" % print_args)

if not codes:

print("FPS %f" % clock.fps())

uart.write( code.payload)

time.sleep(1000)

2018-04-25 08:39
I
网红小智智 星瞳科技

代码格式不对,看不了

新人先看一下 必看:玩转星瞳论坛了解一下图片上传,代码格式等问题。