3

i try to get and recognize ring when anyone call to my phone number, but when i get a call with my modem(phone number), the DataReceieved Event does not work. what is the problem? this is my code:

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...";
        }


}

}

Kamyar Safari
  • 420
  • 2
  • 9
  • ...also, most of your code is showing the Form, not the issue. It's best to distill your code to show the issue, and to show all the key components--in this case there's no code hooking your event handler to the event itself. – STW Mar 26 '13 at 20:12

0 Answers0