我知道这是个老问题。我已经阅读了所有解决方案,但效果很好。有时显示呼叫者ID,有时不显示。仅显示振铃。是否有任何方法可确保每次都获取来电显示。这是我当前正在使用的代码
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SetModem();
}
public void SetModem()
{
sp = new SerialPort("COM3", 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();
richTextBoxEx1.Text = dataReceived;
// Do whatever with the data that is coming in.
}
} }