轮询调制解调器以获取传入数据的最佳设计是什么?

发布于 2024-08-04 22:06:39 字数 246 浏览 6 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独守阴晴ぅ圆缺 2024-08-11 22:06:39

我以前写过类似的东西。有一种方法可以使用 AT 命令告诉调制解调器在每次收到 SMS 时向您发出信号。

作为参考,我在嵌入式应用程序中使用了 Maestro 100 GSM 调制解调器

首先,您必须正确初始化调制解调器。我使用文本模式发送短信,但您可能使用不同的模式。从这些中选择你想要的。 AT+CNMI是最重要的。

AT&F0 # Restore factory defaults
ATE0  # Disable command echo
AT+CMGF=1 # Set message format to text mode
AT+CNMI=1,1,0,1,0 # Set new message indicator
AT+CPMS="SM","SM","SM" # Set preferred message storage to SIM

然后您将等待消息通知,如下所示。 (不要匹配索引号,这可能会因通知而异)

+CMTI: "SM",0 # Message notification with index

当您收到该通知时,检索未读短信:

AT+CMGL="REC UNREAD"  # Retrieve unread messages

我建议您还添加一次民意调查,也许每 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.

AT&F0 # Restore factory defaults
ATE0  # Disable command echo
AT+CMGF=1 # Set message format to text mode
AT+CNMI=1,1,0,1,0 # Set new message indicator
AT+CPMS="SM","SM","SM" # Set preferred message storage to SIM

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)

+CMTI: "SM",0 # Message notification with index

When you get that notification, retrieve the unread SMS's:

AT+CMGL="REC UNREAD"  # Retrieve unread messages

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!

白龙吟 2024-08-11 22:06:39

我发现我记不住很多与短信相关的 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文