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

请忽略计时器代码,因为它仅用于动画。

4

1 回答 1

1

你试过这个PinChanged活动吗?通常,当远端断开连接时,Carrier Detect 会变低。

于 2012-06-05T21:47:55.650 回答