2

The Label on the UI keeps reading "RING RING" and then back to empty "". It doesn't however display the incoming number, which is what I want. I tried to add an if function checking if there is a '0' in the data but that for some reason still doesn't work.

The following is my code:

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
    {
        public CallerID()
        {
            InitializeComponent();
            port.Open();
            WatchModem();
            SetModem();
        }

        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.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('0'))
                    lblCallerIDTitle.Invoke(new SetCallerIdText(() => lblCallerIDTitle.Text = ReadData));
            }
            else
                lblCallerIDTitle.Text = ReadData;
        }
    }
}
4

2 回答 2

2

自从我使用调制解调器以来已经有一段时间了,但是您的调制解调器必须支持 CallerID(我相信现在大多数都支持),您必须从您的电信公司获得 CallerID 服务(我相信您支持),最后,在初始化期间将有一个 AT 命令发送到调制解调器以打开 CallerID 报告。根据您使用的调制解调器型号,命令可能会有所不同,但通常是AT#CID=1. 您的调制解调器手册应该有使用的 AT 代码。

请注意,传入号码本身是在第一次和第二次响铃之间发送的。

于 2012-06-06T15:17:13.630 回答
1

这可能会为您指明正确的方向。

http://www.yes-tele.com/modem.html

于 2012-06-05T16:20:11.393 回答