How to make caller id in c#.net

2019-01-23 22:20发布

问题:


I know this is answered question however I want to know hardware required and how to setup.

I am trying to build a take-out's delivery system wherein users call and their phone number gets captured on a WINFORM.

I googled and it says I need to use TAPI API. That's fine but do I need to connect anything to the PC or will just using TAPI work?

This Link explains it in VB.net. I am looking for it in c#.net. I have also gone through the links provided here.

But nowhere does it explain the setup. So please help.

回答1:

First thing

  • See if your hardware supports caller ID
  • Add the serial port control, set it to whatever comm port your modem is on and watch for the CALLER ID number, then react

To see if your modem supports Caller ID open a serial port terminal (I like putty) and set it to the com port of your modem then call the phone number attached to that that modem, you should see something like RING 5555555555 (where 5555555555 is the phone number of the person calling you)

You may have to turn caller id on for that modem (if so)

1) Open the "Phone And Modem Options" control panel

2) Click the "Modems" tab

3) Select your modem in the list (if it is not already selected)

4) Click the "Properties" button

5) Click the "Advanced" tab

6) Type "#CID=1" into the "Extra initialization commands" edit box Note: replace "#CID=1" with the command to enable caller id on your modem Do not include the "AT" part of the command Do not include the quotes 7) Click OK

8) Click OK

9) restart the computer

Here is some code for interacting with a serial port in c# (incase you need that)

public SerialPort sp;
string dataReceived = string.Empty;
private delegate void SetTextDeleg(string text);

private void FormLoad()
{
 sp = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);
 this.sp.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);
 sp.Open();
}

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();

  // Do whatever with the data that is coming in.
}

Also I just searched amazon for "Caller ID Modem" and there seem to be alot for between 10 and 20 dollars (US) that support this exact use. I would recommend the Trendnet TFM-561U



回答2:

If you are using a phone and fax modem, just plug-in your telephone line into the modem.

Next on your windows form drag-n-drop a SerialPort control and initialize it.

    this.serialPort1.PortName = "COM3"; 
    this.serialPort1.BaudRate = 9600;
    this.serialPort1.DataBits = 8;
    this.serialPort1.RtsEnable = true;
    this.serialPort1.DataReceived += serialPort1_DataReceived;
    this.serialPort1.Open();      

Pass the following command to modem in order to activate Caller-ID

    this.serialPort1.WriteLine("AT#cid=1" + System.Environment.NewLine);

Handle its DataReceived event and display the received data

     void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
     {
          richTextBox1.Text += this.serialPort1.ReadLine();          
     }

Output:

RING               //On 1st Ring
DATE = xxxxx       //On 2nd Ring
TIME = xxxx
NMBR = xxxxxxxxx

RING               //On 3rd Ring    
RING               //On 4th Ring

P.S. If the telephone line sends DTMF tones as Caller-ID then you need DTMF to FSK converter to detect the number, or else you will receive the rings but not the number.