I am new to AT commands. I am using Nokia E71 to send and receive SMS. I am designing an application for sending SMS, but my code is not working.
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;
using System.Threading;
namespace AT_commands
{
public partial class Form1 : Form
{
SerialPort serialPort;
public Form1()
{
InitializeComponent();
}
public void Form1_Load(object sender, EventArgs e)
{
this.serialPort = new SerialPort();
this.serialPort.PortName = "COM23";
this.serialPort.BaudRate = 9600;
this.serialPort.Parity = Parity.None;
this.serialPort.DataBits = 8;
this.serialPort.StopBits = StopBits.One;
this.serialPort.Handshake = Handshake.RequestToSend;
this.serialPort.DtrEnable = true;
this.serialPort.RtsEnable = true;
this.serialPort.NewLine = System.Environment.NewLine;
send_sms();
}
public bool send_sms()
{
label1.Text = "Loaded Successfuly";
String SMSMessage = "Message to send";
String CellNumber = "+923333333333";
String messageToSend = null;
if (SMSMessage.Length <= 160)
{
messageToSend = SMSMessage;
}
else
{
messageToSend = SMSMessage.Substring(0, 160);
}
if (this.IsOpen == true)
{
this.serialPort.WriteLine(@"AT" + (char)(13));
Thread.Sleep(200);
this.serialPort.WriteLine("AT+CMGF=1" + (char)(13));
Thread.Sleep(200);
this.serialPort.WriteLine(@"AT+CMGS=""" + CellNumber + @"""" + (char)(13));
Thread.Sleep(200);
this.serialPort.WriteLine(SMSMessage + (char)(26));
return true;
}
return false;
}
public void Open()
{
if (this.IsOpen == false)
{
this.serialPort.Open();
}
}
public void Close()
{
if (this.IsOpen == true)
{
this.serialPort.Close();
}
}
public bool IsOpen
{
get
{
return this.serialPort.IsOpen;
}
}
public void Dispose()
{
if (this.IsOpen)
this.Close();
}
}
}
Please help me with this code!