AT命令发送短信不工作在Windows 8.1 [英] AT Commands to Send SMS not working in Windows 8.1

查看:240
本文介绍了AT命令发送短信不工作在Windows 8.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究现在超过两天,试图让一个应用程序使用,以发送短信AT命令,我实现了一些教程和项目可在网上。不幸,他们没有工作。

I have been researching now for more than two days, trying to make an app to send SMS using AT Command, I implemented few tutorials and projects available on web. Unluckily, none of them worked.

[https://docs.google.com/document/d/1VfBbMcKZsutP8Cwg2iu7Rqiyccks1J6N2ZEbkbxnCTU/$p$pview本code给我执行命令,但不发送消息。

[https://docs.google.com/document/d/1VfBbMcKZsutP8Cwg2iu7Rqiyccks1J6N2ZEbkbxnCTU/preview ] This code gives me Command executed, but message is not sent.

然后我尝试另一个项目(我使用C#和Visual Studio 2013),已下列文件,执行后,状态变为消息发送的,但我没有收到消息。我使用的华为移动连接 - 3G的应用程序接口的GSM调制解调器

Then I tried another project (I am using C# and Visual Studio 2013), which have following files, After execution the status is changes to Message Sent, but I do not receive Message. I am using HUAWEI Mobile Connect - 3G Application Interface GSM Modem

的Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CSharp_SMS
{
static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form_SMS_Sender());
    }
}
}

Form1.cs中

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CSharp_SMS
{
public partial class Form_SMS_Sender : Form
{
    private SerialPort _serialPort;
    public Form_SMS_Sender()
    {
        InitializeComponent();
    }

    private void buttonSend_Click(object sender, EventArgs e)
    {
        string number = textBoxNumber.Text;
        string message = textBoxMessage.Text;

        _serialPort = new SerialPort("COM17", 19200);   //Replace "COM7" with corresponding port name

        Thread.Sleep(1000);

        _serialPort.Open();

        Thread.Sleep(1000);

        _serialPort.Write("AT+CMGF=1\r");

        Thread.Sleep(1000);

        _serialPort.Write("AT+CMGS=\"" + number + "\"\r\n");

        Thread.Sleep(1000);

        _serialPort.Write(message + "\x1A");

        Thread.Sleep(1000);

        labelStatus.Text = "Status: Message sent";

        _serialPort.Close();
    }
}
}

有问题的程序?难道我错过了什么东西?或者,有问题在Windows 8.1中运行这个,因为我还发现,有一个名为MS超级终​​端程序,其中的一部分是我也不清楚。

Is there problem in the program? Did I missed any thing? Or, there's problem to run this in Windows 8.1, cause I also found that there is a program called MS HyperTerminal, which part of that is not clear to me.

推荐答案

我已经使用 AT指令在下面的格式,它的工作原理。

I have used AT Commands in following format and it works.

public bool sendMsg(string smsid, string PhoneNo, string Message, string from, string to)


{
    string recievedData;
    bool isSend = false;
    string text = "Hello " + to + ",\n" + Message + "\n\n" + from;
    if (!port.IsOpen)                
        port = OpenPort();
    recievedData = ExecCommand(port, "AT+CMGF=1", 400, "Failed to set message format.");

    try
    {
        //string recievedData; // = ExecCommand(port, "AT", 3000, "No phone connected");
        String command = "AT+CMGS=\"" + PhoneNo + "\"";
        recievedData = ExecCommand(port, command, 1000, "Failed to accept phoneNo");
        command = text + char.ConvertFromUtf32(26) + "\r";
        recievedData = ExecCommand(port, command, 1000, "Failed to send message");
        if (recievedData.Contains("OK"))
        {
            isSend = true;                  
        }
        else if (recievedData.Contains("ERROR"))
        {
            isSend = false;                
        }
    }
    catch (Exception ex)
    {
        MyLog.Write(new LogPacket(ex, DateTime.Now));
    }
    return isSend;
}

这篇关于AT命令发送短信不工作在Windows 8.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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