轮询调制解调器以获取传入数据的最佳设计是什么? [英] What is the best design for polling a modem for incoming data?

查看:28
本文介绍了轮询调制解调器以获取传入数据的最佳设计是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 GSM 调制解调器连接到我的计算机,我想使用我编写的 python 程序接收发送给它的文本消息,我只是想知道轮询数据的最佳技术是什么.

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.

我是否应该编写一个具有无限循环的程序,该程序不断检查传入的短信,即在循环内程序发送 AT 命令并读取输入数据.或者调制解调器是否有一种方式来发送传入数据(短信)的应用程序.

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).

我试图将手机想象成一个 GSM 调制解调器,当收到短信时,手机会提醒您该事件,或者手机软件是否具有轮询传入数据的无限循环.

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.

推荐答案

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

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.

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

For reference, I was using a Maestro 100 GSM Modem in an embedded application.

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

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

我建议您也添加一次投票,可能每 5 分钟左右一次,以防您错过通知.使用串行通信,您永远无法确定!

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!

这篇关于轮询调制解调器以获取传入数据的最佳设计是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆