我想使用 C# 从 GSM 调制解调器调用电话。我编写了以下代码。但我无法调用电话。请告知错误是什么。另请让我知道如何处理来自调制解调器的代码中的响应,以便我可以显示“调用连接”或“无法连接”等消息。
private void button1_Click(object sender, EventArgs e)
{
SerialPort po = new SerialPort();
po.PortName = "COM3";
po.BaudRate = int.Parse( "9600");
po.DataBits = Convert.ToInt32("8");
po.Parity = Parity.None;
po.StopBits = StopBits.One;
po.ReadTimeout = int.Parse("300");
po.WriteTimeout = int.Parse("300");
po.Encoding = Encoding.GetEncoding("iso-8859-1");
po.Open();
po.DtrEnable = true;
po.RtsEnable = true;
po.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
po.Write("ATD9030665834;");
}
public void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
if (e.EventType == SerialData.Chars)
{
//what to write here to display the response??
}
}
最佳答案
使用 port.WriteLine("ATD"+phno+";");
这肯定能解决你的问题..
并使用 port.ReadExisting() 处理响应并与您的要求进行比较。就这么简单:)
祝你好运..
关于c# - 在 C# 中从 gsm 调制解调器调用电话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11445313/