0

I am currently using the following Code to Send SMS using AT Command

using (var sp = new SerialPort(CBComPort.Text))
{
    sp.Open();
    sp.WriteLine("AT" + Environment.NewLine);
    sp.WriteLine("AT+CMGF=1" + Environment.NewLine);
    sp.WriteLine("AT+CMGS=\"" + TBPhoneNo.Text + Environment.NewLine);
    sp.WriteLine(TBSMS.Text + (char)26);
}

My question is: can I receive a confirmation message from service center whether the sms is sent or not as when I send SMS from my mobile I receive it or is there any other way to confirm it

kashif
  • 3,713
  • 8
  • 32
  • 47
  • 2
    No, no, no! Please do not process AT commands in this way. You **MUST** wait for the final result code (e.g. OK, ERROR, ...) before sending the next command. And specifically for AT+CMGS you **MUST** wait for the modem to send "\n\r> " before you should start sending MyMessage. See this answer for more details, http://stackoverflow.com/a/15591673/23118. – hlovdal Mar 25 '13 at 10:43
  • @hlovdal thanks for giving some response to my question. you say I should wait for the final result code(e.g. Ok, ERROR), right? How can I do that. will I recive anything like OK or ERROR from my modem. if I receive OK then I should process another command? and if I receive ERROR, do I need to process the command that got ERROR again? what if I keep receiving OK. Will I be able to get confirmation from service center? I would like to please modify my code in my question according to what you think will be the best. I will be thankful to you – kashif Mar 25 '13 at 15:40
  • The SerialPort class must have a `Read` function. I suggest that you create a SendCommand function that does writing and waiting for the response, e.g. `SendCommand(sp, "AT");` will call WriteLine with the command + carriage return and then read and parse received text looking for a final result code and then return. (Strictly speaking you should use the `S3` value for command line termination, but unless you change it yourself it will always be carriage return, ascii value 13. Environment.NewLine is not necessarily correct, although I suspect it to be "\n\r" which will work.) – hlovdal Mar 25 '13 at 15:56
  • The ITU V.250 specification contains the fundamentals you need to know about for handling AT command, if you have not read it yet I strongly recommend doing so. http://www.itu.int/rec/T-REC-V.250-200307-I/en – hlovdal Mar 25 '13 at 15:58
  • How to respond to command failures is a highly application domain specific issue. For instance if the first AT command fails, this is not critical (although it would be an indication that something is not working) and continuing with the next command can be ok. However if the AT+CMHF fails (say because the phone only supports PDU mode, not uncommon), then continuing with the AT+CMGS command with text mode parameters is meaning less. So there is no general answer on how you should respond to errors. – hlovdal Mar 25 '13 at 16:03

0 Answers0