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