2012-06-05 27 views
1

我有一個程序可以獲取來電號碼,日期和時間。但是我想檢查一下,如果打電話給我的人把電話關了,我該怎麼辦?來電顯示檢查來電是否已結束致電

下面是我目前擁有的代碼:

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using System.IO.Ports; 

namespace CallerID 
{ 
    public partial class CallerID : Form 
    { 
     int timesTicked = 0; 
     Point defaultLocation = new Point(); 
     Point newLocation = new Point(); 
     public CallerID() 
     { 
      InitializeComponent(); 
      port.Open(); 
      SetModem(); // SetModem(); originally went after WatchModem(); 
      WatchModem(); 
      //SetModem(); 
      telephoneTimer.Interval = 16; 
      telephoneTimer.Tick += new EventHandler(telephoneTimer_Tick); 
      defaultLocation = pictureBox1.Location; 
      newLocation = pictureBox1.Location; 

     } 

     void telephoneTimer_Tick(object sender, EventArgs e) 
     { 
      if (timesTicked <= 2) 
       newLocation.X++; 
      if (timesTicked >= 4) 
       newLocation.X--; 
      if (timesTicked == 6) 
      { 
       timesTicked = 0; 
       pictureBox1.Location = defaultLocation; 
       newLocation = defaultLocation; 
      } 
      pictureBox1.Location = newLocation; 
      timesTicked++; 
     } 

     protected override void OnPaint(PaintEventArgs e) 
     { 
      base.OnPaint(e); 
      WatchModem(); 
     } 

     private SerialPort port = new SerialPort("COM3"); 
     string CallName; 
     string CallNumber; 
     string ReadData; 

     private void SetModem() 
     { 
      port.WriteLine("AT+VCID=1\n"); 
      //port.WriteLine("AT+VCID=1"); 
      port.RtsEnable = true; 
     } 

     private void WatchModem() 
     { 
      port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived); 
     } 

     public delegate void SetCallerIdText(); 

     private void port_DataReceived(object sender, SerialDataReceivedEventArgs e) 
     { 
      ReadData = port.ReadExisting(); 
      //Add code to split up/decode the incoming data 
      //if (lblCallerIDTitle.InvokeRequired) 
      if (ReadData.Contains("NMBR")) 
      { 
       lblData.Invoke(new SetCallerIdText(() => lblData.Text = ReadData)); 
      } 
      //else 
      // lblCallerIDTitle.Text = ReadData; 
     } 

     private void lblData_TextChanged(object sender, EventArgs e) 
     { 
      telephoneTimer.Start(); 
      button1.Visible = true; 
     } 
    } 
} 

請忽略定時器代碼,因爲這是隻爲動畫。

+0

API說什麼?有沒有事件呢? –

回答

1

您是否嘗試過PinChanged事件?正常情況下,當遠端斷開連接時,載波檢測會變低。

+0

你可以提供一個如何使用PinChanged的例子源代碼嗎? – Subby

+0

我有一種感覺,調制解調器實際上並不是*在這種情況下的呼叫;在這種情況下,CD線路將不起作用。當調制解調器不是真正的參與者時,我不知道如何做到這一點。 @Subby,確認調制解調器是參與者還是被動觀察者。 – pilotcam

+0

@pilotcam:我也不確定。但是在CD,RI和CTS之間,這個事件很可能被檢測到。 –