简体   繁体   English

使用AT命令发送SMS时遇到错误?

[英]Getting error with sending SMS with AT Commands?

Please have a look at the following code: 请看下面的代码:

#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;
    };

And the cpp file 和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();


}

I am trying to send SMS by accessing the dongle. 我正在尝试通过访问加密狗来发送短信。 The port is correct and the dongle also fine because it responded to my friend's code few hours back. 该端口是正确的,并且加密狗也很好,因为它在几个小时后响应了我朋友的代码。 What am I doing wrong here? 我在这里做错了什么? Have I done anything incorrect with C++/CLI ? 我对C ++ / CLI做任何不正确的事情吗? AT Commands? AT指令?

try adding "CR" "LF" (Carriage Return and Line Feed characters) after each AT command, some GSM dongles (like SIM900) needem in order to work. 请尝试在每个AT命令之后添加“ CR”“ LF”(回车符和换行符),一些GSM加密狗(如SIM900)需要工作。 I hope this helps Regards 希望对您有所帮助

if for win32,.. prefer using 如果是Win32,..则喜欢使用

HFILE OpenFile( LPCSTR lpFileName, // pointer to filename LPOFSTRUCT lpReOpenBuff, // pointer to buffer for file information HFILE OpenFile(LPCSTR lpFileName,//指向文件名的指针LPOFSTRUCT lpReOpenBuff,//指向文件信息缓冲区的指针
UINT uStyle // action and attributes ); UINT uStyle //动作和属性);

with other events,... 与其他事件,...

if using SMS gateway with modem AT command capability, that's fine for direct read and write to COM port if U using cell phone, many of this will not work. 如果使用具有调制解调器AT命令功能的SMS网关,那么如果使用手机通过U直接对COM端口进行读写操作,那就很好了,其中许多功能将无法使用。 example nokia 6070, 3100 model group 诺基亚6070、3100模型组示例

best test it using hyperterminal. 最好使用超级终端对其进行测试。

I used CBuildre6 for 我用了CBuildre6

https://sites.google.com/site/xpressdms/rosegarden https://sites.google.com/site/xpressdms/rosegarden

cheer. 欢呼。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM