如何C#向GSM调制解调器发送AT命令并获得响应
本文关键字:命令 响应 AT GSM 调制解调器 如何 | 更新日期: 2023-09-27 18:29:51
我想得到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命令
如何获得回应
感谢
如果调制解调器上的ECHO关闭,则不会对AT命令做出任何响应。
通过发送ATE1第一个确保启用回波
Thread.Sleep(1000);
_serialPort.WriteLine("ATE1" + "'r");
Thread.Sleep(1000);
_serialPort.WriteLine("AT" + "'r");
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();