Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/152.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用AT命令发送SMS时出错?_C++_.net_Visual Studio 2010_Sms_At Command - Fatal编程技术网

C++ 使用AT命令发送SMS时出错?

C++ 使用AT命令发送SMS时出错?,c++,.net,visual-studio-2010,sms,at-command,C++,.net,Visual Studio 2010,Sms,At Command,请查看以下代码: #pragma once using namespace System::IO::Ports; using namespace System::Text::RegularExpressions; using namespace System::Collections::Generic; ref class SMS { public: SMS(void); void sendMessage(); private:

请查看以下代码:

#pragma once
using namespace System::IO::Ports;
using namespace System::Text::RegularExpressions;
using namespace System::Collections::Generic;

    ref class SMS
    {
    public:
        SMS(void);
        void sendMessage();

    private:
        System::IO::Ports::SerialPort ^port;
    };
和cpp文件

#include "StdAfx.h"
#include "SMS.h"


SMS::SMS(void)
{
    //Initialize the Serial Port
    port = gcnew System::IO::Ports::SerialPort();
    port->PortName = "COM12";
    port->BaudRate = 9600;
    port->Parity = Parity::None;
    port->DataBits = 8;
    port->StopBits = StopBits::One;
    port->Handshake = Handshake::RequestToSend;
    port->DtrEnable = true;
    port->RtsEnable = true;
    port->NewLine = System::Environment::NewLine;

    if(!port->IsOpen)
    {
        port->Open();
    }

    //Set message format
    port->WriteLine("AT+CMGF=1");

    //Turn off echo
    port->WriteLine("ATE0");

    //Set memory configurations
    port->WriteLine("AT+CPMS=\"ME\",\"ME\",\"ME\"");





}


//This method will send the SMS

void SMS::sendMessage()
{
    if(!port->IsOpen)
    {
        port->Open();
    }

    port->WriteLine("AT+CMGS=\"012121212\"");
    port->WriteLine("Test Message From C#");
    port->WriteLine(System::Convert::ToString((char)(26)));

    port->Close();


}
我试图通过访问加密狗发送短信。端口是正确的,加密狗也很好,因为它在几个小时前响应了我朋友的代码。我做错了什么?我用C++/CLI做了什么不正确的事情吗?在指挥部

尝试在每个AT命令后添加“CR”“LF”(回车符和换行符),一些GSM加密狗(如SIM900)需要它们才能工作。我希望这有帮助 对于win32,。。 喜欢使用

文件开放文件( LPCSTR lpFileName,//指向文件名的指针 LPOFSTRUCT lpreseponbuff,//指向文件信息缓冲区的指针
UINT uStyle//操作和属性 );

与其他事件一起

如果使用具有调制解调器AT命令功能的SMS网关,则可以直接读取和写入COM端口 如果你使用手机,很多都不起作用。诺基亚6070、3100型号组示例

最好使用超级终端进行测试

我用CBuildre6来做

加油