首页 > 解决方案 > 使用while循环无法获取所有消息

问题描述

我想使用 while 循环从调制解调器中一一获取所有消息,但它不起作用。我的代码有什么问题。

def readInbox():
try:
    inboxempty = False
    while inboxempty == False:
        msg = WriteCMDwith_sleep("AT+CPMS?\r",2)
        smschk = CleanData(msg)
        smschk = smschk.split('SM', maxsplit=1)[-1]\
            .split(maxsplit=1)[0]
        if smschk > "0":
            balmsg = WriteCMDwith_sleep('AT+CMGL="ALL"\r',2)
            cleanRdata = CleanData(balmsg)
            parseAll = cleanRdata.split("+CMGL:")
            parsemsg = parseAll[1]
            smsIndex = parsemsg.partition(' ')[0]
            if (insert_message(parsemsg) == True):
                WriteCMDwith_sleep("AT+CMGD="+smsIndex+"\r",2)
        else:
            inboxempty = True
            break
except Exception as e:
    print(e)

标签: while-loopat-command

解决方案


推荐阅读