我想获得AT命令响应
我想从我的GSM调制解调器读取短信。
我在谷歌上安装了一些代码,这个脚本发送AT命令但没有获得响应
这是我的代码:
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("COM6", 115200);
Thread.Sleep(1000);
_serialPort.Open();
Thread.Sleep(1000);
_serialPort.WriteLine("AT" + "\r");
Thread.Sleep(1000);
string status = _serialPort.ReadLine();
labelStatus.Text = "|-"+ status + "-|";
_serialPort.Close();
}
}
}
这段代码不起作用
没有得到回应,但发送AT命令
如何得到回应?
感谢
答案 0 :(得分:2)
celu.RtsEnable = true;
celu.DtrEnable = true;
celu.WriteBufferSize = 3000;
celu.BaudRate = 9600;
celu.PortName = "COM26"; // You have check what port your phone is using here, and replace it
celu.Open();
//string cmd = "AT+CLIP=1"; // Here you put your AT command
//celu.WriteLine(cmd);
celu.WriteLine ("AT+CLIP=1"+"\r");
Thread.Sleep(500);
//celu.Open();
string ss = celu.ReadExisting();
答案 1 :(得分:1)
如果调制解调器上的ECHO关闭,您将无法对AT命令做出任何响应。
首先发送ATE1确保启用回声
Thread.Sleep(1000);
_serialPort.WriteLine("ATE1" + "\r");
Thread.Sleep(1000);
_serialPort.WriteLine("AT" + "\r");