while-loop - 使用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)
解决方案
推荐阅读
- android - 是否可以在 Android 或 iOS 设备上跟踪访问过的 URL?
- c# - C# 通用列表比较并获取不匹配的行
- swift - 我试图理解 Swift 中的 Optionals。代码有效,但我不明白为什么
- ios - Swift 中的网络请求不规则超时(使用 Alamofire)
- r - 在新数据框中使用因子变量时如何保持水平
- r - 浮动目录在交互式 RMarkdown 中不起作用
- c# - C# 在嵌入 WPF 时设置 Spellcheck.IsEnabled 时出错
- amazon-cloudformation - 如果 EC2 cfn-init 失败,则 CloudFormation 堆栈失败
- python - 将 json 数据写入 json 文件时出现 JSON.parse 错误
- dart - 如何检查类型参数是否是 Dart 中的特定类型?