Read data from GSM modem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ghjk
    Contributor
    • Jan 2008
    • 250

    Read data from GSM modem

    I'm write code to read data from GSM modem. but it couldn't read modem response. Could you please help me? I'll post my code.
    [PHP]using System;
    using System.Collecti ons.Generic;
    using System.Componen tModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows. Forms;
    using System.IO.Ports ;
    using System.Threadin g;
    using System.Timers;
    using System.Diagnost ics;

    namespace rainfall
    {
    public partial class Form1 : Form
    {
    //create an Serial Port object
    SerialPort sp = new SerialPort();

    public Form1()
    {
    InitializeCompo nent();
    }

    private void Form1_Load(obje ct sender, EventArgs e)
    {

    }

    private void btn_Start_Click (object sender, EventArgs e)
    {
    sp.BaudRate = 19200;
    sp.ReceivedByte sThreshold = 1;


    try
    {
    //Open serial port
    sp.PortName = "COM1";
    sp.Open();

    }
    catch (System.Excepti on ex)
    {
    lblError.Text = ex.Message;
    }
    }

    private void btn_Write_Click (object sender, EventArgs e)
    {
    try
    {
    //Write line to serial port
    //sp.Write(texSms .Text + "\r\n");
    sp.Write(txt_Sm s.Text + "\r\n");
    //texSms.Text = "";
    txt_Sms.Text = "";
    }
    catch (System.Excepti on ex)
    {
    lblError.Text = ex.Message;
    }
    //Thread.Sleep(20 0);
    //Set time delay
    //System.Threadin g.Thread.Sleep( 30);
    //sp.WriteTimeout = 200;
    }

    private void btn_Read_Click( object sender, EventArgs e)
    {
    try
    {
    //Cler text box
    //Read serial port and displayed the data in text box
    Thread current = Thread.CurrentT hread;
    Thread.Sleep(10 00);
    txt_Sms.Text = sp.ReadExisting ();
    //texSms.Text = sp.ReadExisting ();
    sp.Write("Conne cted" + "\nS");

    }
    catch (System.Excepti on ex)
    {
    lblError.Text = ex.Message;
    }
    }
    }
    }[/PHP]
  • nmsreddi
    Contributor
    • Jul 2006
    • 366

    #2
    Hi

    the code what you have written is almost correct, make sure that the baud rate you are using matches with the modem you are using .

    are you able to get response from hyperterminal which proves that your modem is working fine .

    as far as code is considered what you have used is correct ,better check other things connection cable and your hardware.


    Regards
    nmsreddi

    Comment

    Working...