Click here to Skip to main content
15,887,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I made a caller ID app using C# 4.5. I am able to get phone number , however, number I get is on 3rd or 4th ring .
I would like to get Number on first or second to avoid call drop or delay in picking up.

Here's my code :

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
using System.Threading;

namespace callerid
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public SerialPort sp;
        string dataReceived = string.Empty;
        private delegate void SetTextDeleg(string text);


        private void Form1_Load(object sender, EventArgs e)
        {
            sp = new SerialPort("COM4", 9600, Parity.None, 8, StopBits.One);
            this.sp.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);
            try
            {
                sp.Open();
            }
            catch (Exception ex)
            {
                sp.Close();
                sp.Open();
            }
            this.sp.WriteLine("AT#cid=1" + System.Environment.NewLine);
            this.WindowState = FormWindowState.Minimized;
            //notifyIcon1.Icon = SystemIcons.Application;
            //this.serialPort1.WriteLine("AT#cid=1" + System.Environment.NewLine);
        }
        void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            try
            {
                Thread.Sleep(500);
                string x = sp.ReadLine(); // will read to the first carriage return
                this.BeginInvoke(new SetTextDeleg(si_DataReceived), new object[] { x });
            }
            catch
            { }
        }

        private void si_DataReceived(string data)
        {
            dataReceived = data.Trim();
            textBox1.Text = dataReceived;
           
            richTextBox1.Text = dataReceived+richTextBox1.Text;
           
        }

        
                
    }
}



Is there any AT Command which I can change.

Thanks

What I have tried:

I tried using HyperTerminal , there I get
RING

DATE = xxxxx

TIME = xxxx

NMBR = xxxxxxxxx

NAME = xxxxxxxx

RING

RING …

On first ring , but using my code I get data one by one after each ring
Posted
Comments
Peter_in_2780 12-Feb-16 1:31am    
Try reading more than one line in sp_DataReceived. Suck it dry, maybe in a loop with smaller sleep() time.
markwhite1 12-Feb-16 1:36am    
If you could help me out with the sample code , that would be great

1 solution

Figured out the solution
instead of :

C#
string x = sp.ReadLine(); 

I wrote :
C#
string x = sp.ReadExisting();


And by this I am getting whole data at once.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900