using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO.Ports; using System.Threading; namespace callerid { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public SerialPort sp; string dataReceived = string.Empty; private delegate void SetTextDeleg(string text); private void Form1_Load(object sender, EventArgs e) { sp = new SerialPort("COM4", 9600, Parity.None, 8, StopBits.One); this.sp.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived); try { sp.Open(); } catch (Exception ex) { sp.Close(); sp.Open(); } this.sp.WriteLine("AT#cid=1" + System.Environment.NewLine); this.WindowState = FormWindowState.Minimized; //notifyIcon1.Icon = SystemIcons.Application; //this.serialPort1.WriteLine("AT#cid=1" + System.Environment.NewLine); } 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(); textBox1.Text = dataReceived; richTextBox1.Text = dataReceived+richTextBox1.Text; } } }
string x = sp.ReadLine();
string x = sp.ReadExisting();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)