使用我的拨号调制解调器呼叫时,DataReceived(串行端口)事件不起作用

时间:2013-03-26 18:26:46

标签: c# events ports

当有人拨打我的电话号码时,我会尝试识别铃声,但是当我接到调制解调器(电话号码)时,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...";
        }


}

}

0 个答案:

没有答案