当有人拨打我的电话号码时,我尝试获取并识别铃声,但是当我用我的调制解调器(电话号码)接听电话时,DataReceieved 事件不起作用。问题是什么?这是我的代码:
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
delegate void SetTextCallback(string text);
private void SetText(string text)
{
if (this.lblStatus.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { text });
}
else
this.lblStatus.Text = text;
}
private void sp1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
string rs = sp1.ReadExisting();
MessageBox.Show(rs);
if (rs.Contains("NMBR"))
{
int sx = rs.IndexOf("NMBR");
SetText("Incomming Call From: " + rs.Substring(sx + 7, 11));
}
}
private void Form1_Load(object sender, EventArgs e)
{
if (sp1.IsOpen)
sp1.Close();
sp1.Open();
sp1.Write("AT+SCID=1;" + Environment.NewLine);
sp1.Write("AT+FCLASS=0;" + Environment.NewLine);
sp1.Write("AT+VCID=1;" + Environment.NewLine);
sp1.Write("AT+PCW=0;" + Environment.NewLine);
lblStatus.Text = "Ready...";
}
}
}