locked
Send and read received message on gsm modem RRS feed

  • Question

  • Hi

    I am new to c# and "AT" commands, i am developing an application which can send and read message from GSM Modem, but i am facing problem when i executing AT command through c# at certain time i works fine but sometime it's not why so?

    i have pasted my code below please tell me the problem.......

    class ListPorts
        {

            public SerialPort port;
            #region Constructor
            public ListPorts()
            {
                try
                {
                    port = new SerialPort("COM16");
                    port.Open();
                    port.BaudRate = 9600;
                    port.DataBits = 8;
                    port.StopBits = StopBits.One;
                    port.ReadTimeout = 300;             //300
                    port.WriteTimeout = 300;
                    port.DiscardOutBuffer();
                    port.DiscardInBuffer();
                    modemDetails();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            #endregion
            private void modemDetails()
            {
                try
                {
                    string responce;
                    port.Write("AT\r");
                    responce = port.ReadExisting();
                    Console.WriteLine(responce);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
            static void Main(string[] args)
            {
                ListPorts lp = new ListPorts();
                
                Console.ReadKey();
            }
        }
    }

    sometime it shows "OK" and sometime nothing.........

    pls tell me the problem.

    Thanks in advance

           
    Thursday, September 5, 2013 2:42 PM