无法使用 AT 命令发送短信

2024-01-03

我在用QextSerialPort访问端口

#include <qstring.h>
#include <qdebug.h>
#include <QCoreApplication>



int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
    QextSerialPort *port;
    QString portName;

    int counter=0;

    //Navigate through ports untill you find huwawei USB dongle
    while(counter<ports.size())
    {
     portName = ports[counter].portName;
    QString productId= ports[counter].productID;
    QString physicalName = ports[counter].physName;
    QString vendorId = ports[counter].vendorID;
    QString friendName = ports[counter].friendName;


    string convertedPortName = portName.toLocal8Bit().constData();
    string convertedProductId = productId.toLocal8Bit().constData();
    string convertedPhysicalName = physicalName.toLocal8Bit().constData();
    string convertedVendorId = vendorId.toLocal8Bit().constData();
    string convertedFriendName = friendName.toLocal8Bit().constData();

    cout << "Port Name: " << convertedPortName << endl;
    cout << "Product ID:" << convertedProductId << endl;
    cout << "Physical Name: " << convertedPhysicalName << endl;
    cout << "Vendor Id: " << convertedVendorId << endl;
    cout << "Friend Name: " << convertedFriendName << endl;
    cout << endl;
    counter++;


    //Break if you found Huwawei USB dongle, assign the port to a new port

    if (std::string::npos != convertedFriendName.find("HUAWEI Mobile Connect - 3G Modem"))
    {
      std::cout << "found!" << std::endl;
      port = new QextSerialPort(portName);
      break;
    }
    }


    //Write and send the SMS
    port->open(QIODevice::ReadWrite) ;
    cout << port->isOpen() << endl;
    port->write("AT+CFUN=1");
    port->write("AT+CMGF=1 ");
    port->write("AT+CMGS=1234567");
    port->write("Hello Test SMS");
    //port->write("0x1A");
    port->flush();

    port->close();
    cout << port->isOpen() << endl;

    system("pause");
    return 0;

}

在此代码中,我尝试使用 AT 命令发送短信。我的加密狗是华为 USB 加密狗。无论如何,它被称为“MegaFone 调制解调器”。

在我的代码中,我实际上无法发送任何短信。这是为什么?请注意,运行此代码时必须编辑电话号码。我对 QT、USB 编程和 AT 命令非常陌生。我什至不知道我是否访问了正确的端口,因为有3个端口属于华为。我的输出如下。

UPDATE

#include <qstring.h>
#include <qdebug.h>
#include <QCoreApplication>



int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
    QextSerialPort *port;
    QString portName;

    int counter=0;

    //Navigate through ports untill you find huwawei USB dongle
    while(counter<ports.size())
    {
     portName = ports[counter].portName;
    QString productId= ports[counter].productID;
    QString physicalName = ports[counter].physName;
    QString vendorId = ports[counter].vendorID;
    QString friendName = ports[counter].friendName;


    string convertedPortName = portName.toLocal8Bit().constData();
    string convertedProductId = productId.toLocal8Bit().constData();
    string convertedPhysicalName = physicalName.toLocal8Bit().constData();
    string convertedVendorId = vendorId.toLocal8Bit().constData();
    string convertedFriendName = friendName.toLocal8Bit().constData();

    cout << "Port Name: " << convertedPortName << endl;
    cout << "Product ID:" << convertedProductId << endl;
    cout << "Physical Name: " << convertedPhysicalName << endl;
    cout << "Vendor Id: " << convertedVendorId << endl;
    cout << "Friend Name: " << convertedFriendName << endl;
    cout << endl;
    counter++;


    //Break if you found Huwawei USB dongle, assign the port to a new port

    if (std::string::npos != convertedFriendName.find("HUAWEI Mobile Connect - 3G Modem"))
    {
      std::cout << "found!" << std::endl;
      port = new QextSerialPort(portName);
      break;
    }
    }


    //Write and send the SMS
    port->open(QIODevice::ReadWrite) ;
    cout << port->isOpen() << endl;
    port->write("AT+CFUN=1\n");
    cout << "\n";
    port->write("AT+CMGF=1 \n ");
    cout << "\n";
    port->write("AT+CMGS=0776255495\n");
    cout << "\n";
    port->write("Hello Test SMS\n");
    cout << "\n";
    //port->write("0x1A");
    port->flush();

    port->close();
    cout << port->isOpen() << endl;

    system("pause");
    return 0;

}

您的问题如下:

port->write("AT+CFUN=1");
port->write("AT+CMGF=1 ");
port->write("AT+CMGS=1234567");
port->write("Hello Test SMS");

总是在向调制解调器发送 AT 命令行后,您MUST等待最终结果代码(例如通常OKor ERROR尽管还有更多,但您必须准备好处理所有这些。关于如何等待最终结果代码的示例,可以查看源码atinout http://atinout.sourceforge.net/,这是一个小程序,用于读取 AT 命令列表,将它们发送到调制解调器并打印响应)。

因为不等待以下命令将中止当前正在执行的命令。 AT 命令的中止在 V.250 中的“5.6.1 中止命令”部分中定义。如果您对处理 AT 命令缺乏经验,那么该规范是必读的。此外,您还可以阅读 27.005 来了解您使用的 +CMG... 命令。您可以在以下位置找到规格链接:at命令标签信息 https://stackoverflow.com/tags/at-command/info.

For AT+CMGS具体来说,您还必须在发送文本之前等待“\r\n>”,请参阅我的另一个答案 https://stackoverflow.com/a/15591673/23118r.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法使用 AT 命令发送短信 的相关文章

  • 安装J语言的JQt IDE,出现错误

    我一直按照这里的说明进行操作 http code jsoftware com wiki System Installation Linux http code jsoftware com wiki System Installation L
  • 如何从 C# 中的 dataTable.Select( ) 查询中删除单引号?

    所以我有一个经销商名称列表 我正在我的数据表中搜索它们 问题是 一些傻瓜必须被命名为 Young s 这会导致错误 drs dtDealers Select DealerName dealerName 所以我尝试替换字符串 尽管它对我不起作
  • 以编程方式读取 SQL Server 查询计划建议的 SQL 特定执行的索引?

    如果我在 SSMS 中运行此命令 set showplan xml on GO exec some procedure arg1 arg2 arg3 GO set showplan xml off GO 我获得查询执行中涉及的完整调用堆栈的
  • ComboBox DataBinding 导致 ArgumentException

    我的几个类对象 class Person public string Name get set public string Sex get set public int Age get set public override string
  • 如何判断计算机是否已重新启动?

    我曾经使用过一个命令行 SMTP 邮件程序 作为试用版的限制 它允许您在每个 Windows 会话中最多接收 10 封电子邮件 如果您重新启动计算机 您可能还会收到 10 个以上 我认为这种共享软件破坏非常巧妙 我想在我的应用程序中复制它
  • Visual Studio 在构建后显示假错误

    我使用的是 Visual Studio 2017 构建后 sln在调试模式下 我收到错误 但是 当我通过双击错误列表选项卡中的错误来访问错误时 错误会从页面中消失 并且错误数量也会减少 我不太确定这种行为以及为什么会发生这种情况 有超过 2
  • 使用可变参数包类型扩展的 C++ 函数调用者包装器

    我绑定了一些 API 并且绑定了一些函数签名 如下所示 static bool WrapperFunction JSContext cx unsigned argc JS Value vp 我尝试将对象和函数包装在 SpiderMonkey
  • 启动时的 Excel 加载项

    我正在使用 Visual C 创建 Microsoft Excel 的加载项 当我第一次创建解决方案时 它包含一个名为 ThisAddIn Startup 的函数 我在这个函数中添加了以下代码 private void ThisAddIn
  • C++ 中的双精度型数字

    尽管内部表示有 17 位 但 IEE754 64 位 浮点应该正确表示 15 位有效数字 有没有办法强制第 16 位和第 17 位为零 Ref http msdn microsoft com en us library system dou
  • 高效列出目录中的所有子目录

    请参阅迄今为止所采取的建议的编辑 我正在尝试使用 WinAPI 和 C 列出给定目录中的所有目录 文件夹 现在我的算法又慢又低效 使用 FindFirstFileEx 打开我正在搜索的文件夹 然后我查看目录中的每个文件 使用 FindNex
  • 等待 IAsyncResult 函数直至完成

    我需要创建等待 IAsyncResult 方法完成的机制 我怎样才能做到这一点 IAsyncResult result contactGroupServices BeginDeleteContact contactToRemove Uri
  • Unity:通过拦截将两个接口注册为一个单例

    我有一个实现两个接口的类 我想对该类的方法应用拦截 我正在遵循中的建议Unity 将两个接口注册为一个单例 https stackoverflow com questions 1394650 unity register two inter
  • WebBrowser.Print() 等待完成。 。网

    我在 VB NET 中使用 WebBrowser 控件并调用 Print 方法 我正在使用 PDF 打印机进行打印 当调用 Print 时 它不会立即启动 它会等到完成整个子或块的运行代码 我需要确保我正在打印的文件也完整并继续处理该文件
  • C++ new * char 不为空

    我有一个问题 我在 ASIO 中开发服务器 数据包采用尖头字符 当我创建新字符时 例如char buffer new char 128 我必须手动将其清理为空 By for int i 0 i lt 128 i buffer i 0x00
  • 是否可以在 Qt Creator 中将 Qt 样式表与升级的小部件一起使用?

    我正在尝试使用 Qt 样式表对标准小部件进行一些重大的重新设计 因此 在为不同的小部件手动完成大部分工作之后 objectName选择器 我决定以某种方式对类似的小部件进行分组 例如我有多个QFrames其作用类似于内部表单中的标题 我希望
  • 可访问性不一致:参数类型的可访问性低于方法

    我试图在两个表单之间传递一个对象 基本上是对当前登录用户的引用 目前 我在登录表单中有一些类似的内容 private ACTInterface oActInterface public void button1 Click object s
  • 堆栈是向上增长还是向下增长?

    我在 C 中有这段代码 int q 10 int s 5 int a 3 printf Address of a d n int a printf Address of a 1 d n int a 1 printf Address of a
  • 使用 C 在 OS X 中获取其他进程的 argv

    我想获得其他进程的argv 例如ps 我使用的是在 Intel 或 PowerPC 上运行的 Mac OS X 10 4 11 首先 我阅读了 ps 和 man kvm 的代码 然后编写了一些 C 代码 include
  • 为boost python编译的.so找不到模块

    我正在尝试将 C 代码包装到 python 中 只需一个类即可导出两个函数 我编译为map so 当我尝试时import map得到像噪音一样的错误 Traceback most recent call last File
  • OpenCV SIFT 描述符关键点半径

    我正在深入研究OpenCV的SIFT描述符提取的实现 https github com Itseez opencv blob master modules nonfree src sift cpp 我发现了一些令人费解的代码来获取兴趣点邻域

随机推荐