I'm trying to read sms from GSM modem using c#. my code is only working for at command. When I enter at+cmgr=1 it says"ERROR". but when i typr it hyperterminal. It is working.Could you please tell me what's wrong. I'm posting my code here.
[PHP]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
namespace Rainfall
{
public partial class Form1 : Form
{
//create an Serial Port object
SerialPort sp = new SerialPort();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btnStart_Click(object sender, EventArgs e)
{
sp.BaudRate = 19200;
sp.WriteBufferSize = 1024;
try
{
//Open serial port
sp.PortName = "COM3";
sp.Open();
//sp.Write("Connected" + "\n");
}
catch (System.Exception ex)
{
lblError.Text = ex.Message;
}
}
private void btnWrite_Click(object sender, EventArgs e)
{
try
{
//Write line to serial port
string s = txtSMS.Text + "\r";
//sp.WriteLine("at+CMGR=1\r");
sp.Write(s);
txtSMS.Text = "";
}
catch (System.Exception ex)
{
lblError.Text = ex.Message;
}
}
private void btnRead_Click(object sender, EventArgs e)
{
try
{
//Cler text box
txtSMS.Text = "";
//Read serial port and displayed the data in text box
//txtSMS.Text = sp.ReadLine();
txtSMS.Text = sp.ReadExisting();
}
catch (System.Exception ex)
{
lblError.Text = ex.Message;
}
}
private void btnStop_Click(object sender, EventArgs e)
{
txtSMS.Text = "";
sp.Close();
}
}
}
[/PHP]