Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, anyone please help me.
I have a problem in my C# code to connect my system to the gsm modem serial port:

C#
 private void Form1_Load(object sender, EventArgs e)
        {
            try
            {


                p.PortName = "COM9";
                p.BaudRate = 460800;
                p.DataBits = 8;
                p.StopBits = StopBits.One;
                p.Parity = Parity.None;
                p.ReadTimeout = 300;
                p.WriteTimeout = 300;
                p.Open();
                p.DtrEnable = true;
                p.RtsEnable = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            
            p.Write("AT\r\n");
            String s1 = p.ReadLine();
            if (s1.Equals ("OK"))
            {
                MessageBox.Show("Port is connected");
            }
            else
                MessageBox.Show("Port is not connected");  
        }

        private void button1_Click(object sender, EventArgs e)
        {
           // p.write("");

            p.Write("at+cmgf=1\r\n");
            p.Write("at+cmgs=\"+919842798108\"\r\n");
            
            p.Write("Test message ");
            SendKeys.Send("^(z)");
           
            String s2 = p.ReadLine();
            if (s2.Equals("OK"))
            {
                MessageBox.Show("Message Sent");
            }
            else
                MessageBox.Show("Message not sent");
        }
    }
}


Every time it shows "port is not connected".
Please find the error in my code. And how to connect my gsm modem port with my system?

Hey. Is there any way without using MScomm?
I am using Visual studio 2008.
Please reply me.
Posted
Updated 25-Feb-10 0:00am
v4

Something here [^].

Make sure the steps you follow are similar.
 
Share this answer
 
instead of this code:
C#
if (s1.Equals ("OK"))
{
MessageBox.Show("Port is connected");
}



type
C#
if (s1.Contain ("OK"))
{
MessageBox.Show("Port is connected");
}
 
Share this answer
 
Yes there is.
Check this[^]

Hope this helps!
Ankur
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900