I am developing an application which will read and write data to gsm modem. When i switch off the modem and switch on again, at start up i need to send an AT command so that that modem automatically sets to the settings given for the port. When i give this command in hyper terminal it does not get displayed but the command is sent to modem. and the modem sets itself to the settings that i give for the hyperterminal port settings. From then I can send rest of the commands. But in my application i am unable to send the first AT command, so I am manually doing it via hyper terminal. Why is this not happening through my application? I also tried sending this command using button click, but still it is not executed on the port.
port.Open();
port.DtrEnable = true;
port.RtsEnable = true;
if (port != null)
{
btn_connect.Enabled = false;
btn_disconnect.Enabled = true;
port.WriteLine("AT");
port.WriteLine("AT+CLIP=1");
port.WriteLine("AT+CMGF=1");
con_status.Text = "Connected at " + cboPortName.Text;
}
Port settings that i gave in my application are:
port.PortName = cboPortName.Text;
port.BaudRate = Convert.ToInt32(this.cboBaudRate.Text); //9600
port.DataBits = Convert.ToInt32(this.cboDataBits.Text); //8
port.ReadTimeout = Convert.ToInt32(this.txtReadTimeOut.Text); //300
port.WriteTimeout = Convert.ToInt32(this.txtWriteTimeOut.Text); //300
port.StopBits = StopBits.One; //1
port.Parity = Parity.None; // None
port.Encoding = Encoding.GetEncoding("iso-8859-1");
port.Open();
port.DtrEnable = true;
port.RtsEnable = true;
The problem is solved. Might help some one in the future, this is what I have done.
I added these two lines of settings to my port while connection establishment, which I dint give before.
But I have no idea why adding these settings made the difference and solved my problem, but it worked 🙂