vb.net 如何在 c#.net 中制作来电显示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32984598/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make caller id in c#.net
提问by mark
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.
我正在尝试构建一个外卖交付系统,其中用户呼叫并在 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?
我用谷歌搜索,它说我需要使用 TAPI API。那很好,但我需要将任何东西连接到 PC 还是只使用 TAPI 工作?
This Linkexplains it in VB.net. I am looking for it in c#.net. I have also gone through the links provided here.
此链接在 VB.net 中进行了解释。我正在 c#.net 中寻找它。我还浏览了此处提供的链接。
But nowhere does it explain the setup. So please help.
但它没有解释设置。所以请帮忙。
回答by Someone that matters
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)
要查看您的调制解调器是否支持来电显示,请打开一个串行端口终端(我喜欢 putty)并将其设置为调制解调器的 com 端口,然后拨打该调制解调器附带的电话号码,您应该看到类似 RING 5555555555 的内容(其中 5555555555 是给您打电话的人的电话号码)
You may have to turn caller id on for that modem (if so)
您可能需要为该调制解调器打开来电显示(如果是这样)
1) Open the "Phone And Modem Options" control panel
1) 打开“电话和调制解调器选项”控制面板
2) Click the "Modems" tab
2) 单击“调制解调器”选项卡
3) Select your modem in the list (if it is not already selected)
3) 在列表中选择您的调制解调器(如果尚未选择)
4) Click the "Properties" button
4)点击“属性”按钮
5) Click the "Advanced" tab
5) 单击“高级”选项卡
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
6) 在“额外初始化命令”编辑框中键入“#CID=1” 注意:将“#CID=1”替换为在调制解调器上启用来电显示的命令 不要包含命令的“AT”部分 不要包括引号 7) 单击确定
8) Click OK
8) 点击确定
9) restart the computer
9)重启电脑
Here is some code for interacting with a serial port in c# (incase you need that)
这是一些用于与 c# 中的串行端口交互的代码(以防万一)
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
此外,我刚刚在亚马逊上搜索了“来电显示调制解调器”,似乎有很多 10 到 20 美元(美国)支持这种确切用途。我会推荐 Trendnet TFM-561U
回答by Marshal
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 SerialPortcontrol and initialize it.
接下来在您的 Windows 窗体上拖放一个SerialPort控件并对其进行初始化。
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
处理它的 DataReceived 事件并显示接收到的数据
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.
PS 如果电话线发送 DTMF 音作为来电显示,那么您需要 DTMF 到 FSK 转换器来检测号码,否则您将收到振铃而不是号码。

