logo

uartl连续输入时如何延长等待时间不超时?

2023-02-10 18:26
8
mix2
import time,uos,sensor
import begin,faceTest,faceCollect,luck
from pyb import UART

uart = UART(3, 19200,timeout_char=1000)
while(True):
    if uart.any():
        a = uart.readline().decode()
        print("收到指令:",a)
        if int(a) == 10:
            begin.begin_zero()
            time.sleep_ms(100)
            uart.write("11\n")
            uart.init(9600, bits=8, parity=None, stop=1, timeout_char=1000) # 使用给定参数初始化
            print("初始化完成")
            #luck.luck()
        elif int(a) == 12:
            begin.begin_two()
            faceTest.facedetaction()            #找到对应人脸画框
            faceTest.facetest()                 #人脸匹配
        elif int(a) == 13:
            begin.begin_three()
            sensor.sleep(True)                  # 启用感光元件睡眠模式(节省约40mA)。
            print("休眠模式开启")
        elif int(a) == 14:
            begin.begin_four()
            x = uart.readline().decode()
            print(x)
            faceCollect.we()
        elif int(a) == 15:
            begin.begin_five()
            #print(uos.getcwd())
            x = uart.readline().decode()
            print(x)
            while(x == 15):
                uos.remove(singtown/s%s,(x-10))
                print(x)
                break

    time.sleep_ms(10)

此为输入14时立马再输入14后的结果,时间很赶(文中begin是指示灯),在指示灯灭后输入14即为超时:crying_face:

41de809d-af6c-4895-956e-c0f737745372.png

此为首次输入14时等待一段时间

a74a29d3-53b0-4e36-b045-e4b4c5e143a7.png

问题一:如何让超时限定时间延长,使用户能有足够长的时间输入指令?

问题二:为何输入15时,删除目录指令无效?如何删除目录?

fc18a439-171a-4045-b5e1-e6fa71dc58af.png

谢谢大佬解答,感激不尽:smiling_face_with_open_mouth:

2023-02-13 22:15
I
网红小智智 星瞳科技

在27行上面加入,可以一直等待到有数据。

while not uart.any(): time.sleep(0.01)