using System; using System.Collections.Generic; using System.Threading; using System.IO.Ports; using System.Windows.Forms; using System.Management; using System.Management.Instrumentation; namespace gi { public partial class Form1 : Form { public Form1() { InitializeComponent(); } SerialPort s; private void button1_Click(object sender, EventArgs e) { string comport = cboPorts.Text; GetPort(comport); } public void GetPort(string comport) { // if (this.s == null) { this.s = new SerialPort(); this.s.PortName = comport; this.s.Open(); this.s.BaudRate = 9600; this.s.Parity = Parity.None; this.s.DataBits = 8; this.s.StopBits = StopBits.One; //this.s.Handshake = Handshake.RequestToSend; this.s.DtrEnable = true; this.s.RtsEnable = true; //this.s.RtsEnable = true; this.s.NewLine = System.Environment.NewLine; this.s.WriteLine("AT" + (char)(13)); //string tt = s.ReadLine(); // if(s.ReadLine()!="AT/r/r") { Thread.Sleep(2000); this.s.WriteLine("AT+CMGF=1" + (char)(13)); Thread.Sleep(3000); this.s.WriteLine("AT+CMGS=\"" + 9916518522 + "\""); Thread.Sleep(5000); this.s.WriteLine(">" + "le" + (char)(26)); this.s.Close(); MessageBox.Show("Sent"); } //else //{ // MessageBox.Show("Dervice Nt"); //} } } private void Form1_Load(object sender, EventArgs e) { string[] ports = SerialPort.GetPortNames(); foreach (string port in ports) { cboPorts.Items.Add(port); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)