轮询调制解调器以获取传入数据的最佳设计是什么?
我有一个 GSM 调制解调器连接到我的计算机,我想使用我编写的 python 程序接收发送到它的短信,我只是想知道轮询数据的最佳技术是什么。
我是否应该编写一个具有无限循环的程序,该程序不断检查传入的短信,即在循环内程序发送 AT 命令并读取输入数据。或者调制解调器是否有一种方式向应用程序发出传入数据(短信)的信号。
我试图想象手机只是一个 GSM 调制解调器,当收到短信时,手机会提醒您该事件,或者手机软件是否有一个无限循环来轮询传入的数据。
I have a GSM modem connected to my computer, i want to receive text messages sent to it using a python program i have written, am just wondering what is the best technique to poll for data.
Should i write a program that has a infinite loop that continuously checks for incoming sms's i.e within the loop the program sends the AT commands and reads the input data. or do modems have a way of signaling an application of an incoming data(sms).
Am trying to imagine a cellphone is just a GSM modem, and when an sms is received, the phone alerts you of the event, or does the phone software have an infinite loop that polls for incoming data.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我以前写过类似的东西。有一种方法可以使用 AT 命令告诉调制解调器在每次收到 SMS 时向您发出信号。
作为参考,我在嵌入式应用程序中使用了 Maestro 100 GSM 调制解调器。
首先,您必须正确初始化调制解调器。我使用文本模式发送短信,但您可能使用不同的模式。从这些中选择你想要的。 AT+CNMI是最重要的。
然后您将等待消息通知,如下所示。 (不要匹配索引号,这可能会因通知而异)
当您收到该通知时,检索未读短信:
我建议您还添加一次民意调查,也许每 5 分钟左右一次,以防万一您错过通知。对于串行通信,您永远无法确定!
I have written something similar before. There is a way using AT commands to tell the modem to signal you each time an SMS is received.
For reference, I was using a Maestro 100 GSM Modem in an embedded application.
First you have to initialize the modem properly. I was using text mode for the SMS, but you might be using something different. Pick from these what you want. AT+CNMI is the most important.
You would then wait for a message notification, that will look like this. (Don't match on the index number, that might differ between notifications)
When you get that notification, retrieve the unread SMS's:
I would recommend you also add a poll, maybe every 5 minutes or so, just in case you miss a notification. With serial comms you can never be sure!
我发现我记不住很多与短信相关的 AT 命令集。安德烈·米勒的回答似乎敲响了警钟。无论如何,您应该非常仔细地阅读文档,我确信其中存在一些问题。
我对轮询的建议是至少每 5 秒一次 - 这只是为了在面对断开连接时的鲁棒性和响应能力。
我使用状态机在初始化、读取和删除消息之间导航。
I find I can't remember much of the AT command set related to SMS. Andre Miller's answer seems to ring a few bells. Anyway you should read the documentation very carefully, I'm sure there were a few gotchas.
My recommentation for polling is at least every 5 seconds - this is just for robustness and responsiveness in the face of disconnection.
I used a state machine to navigate between initialisation, reading and deleting messages.