I am working on a project in which I have to send and recieve SMS via GSM modem in C# using AT commands. I am done with the sending part but having trouble reading sms from the sim card. I have tried the following code and get the following response: OK OK ERROR. The code for reading the SMS is :-`
public bool ReadSms()
{
//string buffer = string.Empty;
if (this.serialPort.IsOpen == true)
{
try
{
this.serialPort.WriteLine("AT");
Thread.Sleep(2000);
this.serialPort.WriteLine("AT+CMGF=1" + (char)(13));
Thread.Sleep(3000);
this.serialPort.WriteLine("AT + CMGL = ALL" + (char)(26));
Thread.Sleep(5000);
string a = this.serialPort.ReadExisting();
MessageBox.Show(a);
}
catch (Exception ex)
{
MessageBox.Show(ex.Source);
}
return true;
}
else
return false;
}
public void Opens()
{
if(this.serialPort.IsOpen == false)
{
this.serialPort.Open();
}
}
public void Closes()
{
if (this.serialPort.IsOpen == true)
{
this.serialPort.Close();
}
}
`