单片机先给op发送N识别红并返回给串口坐标但再次发送G识别绿的时候就不行了请问串口数据的发送会占用字符串的识别吗?
-
while (1): if uart.any(): receive=uart.readline().decode() if receive=='N': #when receive 'N',begin to find the color threshold_index=0 #red for 0 print(receive) while(True): img = sensor.snapshot() # Take a picture and return the image. blobs = img.find_blobs([thresholds[threshold_index]]) if blobs: max_blob=find_max(blobs) img.draw_rectangle(max_blob.rect()) img.draw_cross(max_blob.cx(), max_blob.cy()) aim=1 #1 find the aim,0 not find a=max_blob.cx() b=max_blob.cy() #transfer the format become(x,xxx,xxx) if max_blob.cx()<10: a='00'+str(a) if max_blob.cy()<10: b='00'+str(b) elif max_blob.cy()<10: b='00'+str(b) #the case that max_blob.cx or .cy<10 elif max_blob.cx()<100: a='0'+str(a) # print(a) if max_blob.cy()<100: b='0'+str(b) elif max_blob.cy()<100: b='0'+str(b) #the case that max_blob.cx or .cy<100 output_str="[%s,%s,%s]" % (aim,a,b) print('you send:',output_str) uart.write(output_str+'\r\n') #the output foemat is (x,xxx,xxx) else: aim=0 aim="[%s]"%(aim) uart.write(aim+'\r\n') print('not found!') if uart.any(): receiv=uart.readline().decode() if receiv=='G': #the command is the symbol of find green threshold_index=2 #green for 2 while(True): img = sensor.snapshot() # Take a picture and return the image. blobs = img.find_blobs([thresholds[threshold_index]]) if blobs: max_blob=find_max(blobs) img.draw_rectangle(max_blob.rect()) img.draw_cross(max_blob.cx(), max_blob.cy()) aim=1 #1 find the aim,0 not find a=max_blob.cx() b=max_blob.cy() #transfer the format become(x,xxx,xxx) if max_blob.cx()<10: a='00'+str(a) if max_blob.cy()<10: b='00'+str(b) elif max_blob.cy()<10: b='00'+str(b) #the case that max_blob.cx or .cy<10 elif max_blob.cx()<100: a='0'+str(a) print(a) if max_blob.cy()<100: b='0'+str(b) elif max_blob.cy()<100: b='0'+str(b) #the case that max_blob.cx or .cy<100 output_str="[%s,%s,%s]" % (aim,a,b) print('send:',output_str) uart.write(output_str+'\r\n') #the output foemat is (x,xxx,xxx) else: aim=0 aim="[%s]"%(aim) uart.write(aim+'\r\n') print('not found!')
-
你的 if receive=='N'里面又有一个死循环。