赞
踩
import sensor, image, time, math from pyb import UART uart = UART(3,38400) sensor.reset() sensor.set_pixformat(sensor.GRAYSCALE) sensor.set_framesize(sensor.VGA) sensor.set_windowing((640, 50)) sensor.skip_frames(time = 2000) sensor.set_auto_gain(False) sensor.set_auto_whitebal(False) clock = time.clock() 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) long1=code.payload() shuai=code.quality() print("%d" % shuai) FH = bytearray([0xb2,0xb3,int(long1),0xa2,int(shuai)]) uart.write(FH) if not codes: print("FPS %f" % clock.fps())
u8 data,a,b; static u8 step=0; void USART2_IRQHandler(void) //串口1中断服务程序 { if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) //接收中断(接收到的数据必须是0x0d 0x0a结尾) {USART_ClearITPendingBit(USART2,USART_IT_RXNE);//清除中断标志 data= USART_ReceiveData(USART2); switch (step) { case 0: if(data==0xb2) step=1; else {step=0;} break; case 1: if(data==0xb3) step=2; else {step=0;} break; case 2: a=data; step=3; break; case 3: if(data==0xa2) step=4; else step=0; break; case 4: b=data; step=0; break; } } }
这些代码挺简单的认真看能看懂
注意波特率一致
可以分别调试,先用串口助手调试STM32端看指令是否正确-----再使用openmv打印到串口使用16进制显示看显示是否正常
在串口中不要放显示函数之类的(否则会出现显示第一个正确·,显示第二个错误的问题)
OPWNMV的那个代码是识别条形码
bytearray是phthon内置函数,大于255的数字拆分然后在STM32端组装起来
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。