I am just a beginner and i would like to send sms using 5800 nokia piece. What i would like to do is send "at" command to mobile and read response "OK" from the port(sent by the mobile). I can send commands and get response through hyperterminal but it is not working with my code, i learnt that in my code "SerialDataReceivedEventHandler" is not triggering. Please assit me in developing the code.
here is the code i have written.
SerialPort sp = new SerialPort("com1", 9600, Parity.None, 8, StopBits.One);
public AutoResetEvent receivenow;
private void button1_Click(object sender, EventArgs e)
{
try
{
receivenow = new AutoResetEvent(false);
sp.ReadTimeout = 300; //300
sp.WriteTimeout = 300; //300
sp.Encoding = Encoding.GetEncoding("iso-8859-1");
sp.DataReceived += new SerialDataReceivedEventHandler(sp_datareceived);
sp.RtsEnable = true;
sp.DtrEnable = true;
testSMS();
}
catch (Exception ex) { MessageBox.Show(ex.ToString()); }
}
private void testSMS()
{
receivenow = new AutoResetEvent(false);
sp.Open();
sp.DiscardInBuffer();
sp.DiscardOutBuffer();
receivenow.Reset();
sp.WriteLine("AT" + "\r");
}
private void sp_datareceived(object sender, SerialDataReceivedEventArgs args)
{
receivenow.Set();
string responsetocmd = sp.ReadExisting();
label1.Text = responsetocmd;
}
thanks in advance..........