发送短信的 AT 命令在 Windows 8.1 中不起作用 [英] AT Commands to Send SMS not working in 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/preview" ] 这段代码让我执行了命令,但没有发送消息.
[https://docs.google.com/document/d/1VfBbMcKZsutP8Cwg2iu7Rqiyccks1J6N2ZEbkbxnCTU/preview ] This code gives me Command executed, but message is not sent.
然后我尝试了另一个项目(我使用的是 C# 和 Visual Studio 2013),其中包含以下文件,执行后状态更改为 Message Sent,但我没有收到消息.我正在使用 HUAWEI Mobile Connect - 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
");
Thread.Sleep(1000);
_serialPort.Write("AT+CMGS="" + number + ""
");
Thread.Sleep(1000);
_serialPort.Write(message + "x1A");
Thread.Sleep(1000);
labelStatus.Text = "Status: Message sent";
_serialPort.Close();
}
}
}
程序有问题吗?我错过了什么吗?或者,在Windows 8.1中运行这个有问题,因为我还发现有一个叫做MS HyperTerminal的程序,我不清楚其中的一部分.
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 Commands
以下格式并且它有效.
I 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 + ",
" + Message + "
" + 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) + "
";
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屋!