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

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

问题描述

我有一个连接到计算机的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命令并读取输入数据.或调制解调器是否具有信号通知传入数据(sms)应用的方式.

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.

推荐答案

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

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.

首先,您必须正确初始化调制解调器.我在短信中使用文本模式,但您可能使用了其他方式.从这些中选择您想要的. 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

收到该通知后,检索未读的SMS:

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天全站免登陆