通过 AT 命令使用 C#.net 拨号 [英] Dial call using C#.net by AT Commands
问题描述
我想做一个c#程序,通过usb线连接到我的手机上,只需要打电话.我找到了如何通过 SerialPort 连接以及如何通过 AT 命令进行呼叫,但是当我运行我的程序并单击进行呼叫时,没有任何反应.这是我的代码,请帮助我:
I want to make a c# program that connects to my mobile phone by usb cable to make just a call. I found how to connect by SerialPort and how to make call by AT Commands, but when I run my program and click to make the call, nothing happens. This is my code, please Help me:
SerialPort SP = new SerialPort("COM3");
SP.BaudRate = 9600;
SP.Parity = Parity.None;
SP.DataBits = 8;
SP.StopBits = StopBits.One;
SP.RtsEnable = true;
SP.DtrEnable = true;
SP.Encoding = System.Text.Encoding.Unicode;
SP.ReceivedBytesThreshold = 1;
SP.NewLine = Environment.NewLine;
SP.Open();
SP.Write("ATDT 0999182542"+ Environment.NewLine);
SP.Close();
推荐答案
首先要查看你的调制解调器是否已连接,向端口发送一个 AT
命令.如果您收到 OK
作为响应,则表示您的调制解调器已连接.
First of all to see if your modem is connected, send an AT
command to the port. If you get a OK
as response, then it means your modem is connected.
拨打电话的语法是:
ATDYourphnumber;
//不要忘记";"
示例:ATD9012345645;
所以你应该以同样的方式写入端口.
So you should write to the port the same way.
语法:
SP.WriteLine("ATD"+电话号码+";");
您可以使用 WriteLine 因为它也为
服务.
You can use WriteLine since that serves the
too.
更新:如何查看调制解调器的响应:
Update: How to see the response from modem:
SP.Open( ) 之后;
string cmd = "AT";
SP.WriteLine(cmd + "
");
SP.Write(cmd + "
");
Thread.Sleep(500);
string ss= SP.ReadExisting();
if(ss.EndsWith("
OK
"))
{
MessageBox.Show("Modem is connected");
}
这篇关于通过 AT 命令使用 C#.net 拨号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!