I'm experiencing difficulty using AT commands. I've a GSM Modem connected as Com port with my pc. My code works fine when sending sms but the sent message is not in correct format. For example I sent 'Hello World' but the sent message shows '??' in cellphone. Plz guide me where I'm wrong. Here is my code.
try
{
string recievedData = ExecCommand(port, "AT", 300, "No phone connected");
recievedData = ExecCommand(port, "AT+CMGF?", 300, "Failed to accept phoneNo");
recievedData = ExecCommand(port, "AT+CMGF=1", 300, "Failed to set message format.");
string command = "AT+CMGS=\"" + PhoneNo + "\"";
recievedData = ExecCommand(port, command, 300, "Failed to accept phoneNo");
command = "hello world!" + "\x1A";
recievedData = ExecCommand(port, command, 3000, "Failed to send message"); //3 seconds
if (recievedData.EndsWith("\r\nOK\r\n"))
{
isSend = true;
}
else if (recievedData.Contains("ERROR"))
{
isSend = false;
}
return isSend;
}
catch (Exception ex)
{
throw ex;
}
Here is Execute Method
public string ExecCommand(SerialPort port,string command, int responseTimeout, string errorMessage)
{
try
{
port.DiscardOutBuffer();
port.DiscardInBuffer();
receiveNow.Reset();
port.Write(command + "\r");
string input = ReadResponse(port, responseTimeout);
if ((input.Length == 0) || ((!input.EndsWith("\r\n> ")) && (!input.EndsWith("\r\nOK\r\n"))))
throw new ApplicationException("No success message was received.");
return input;
}
catch (Exception ex)
{
throw ex;
}
}