0

I'm trying to send sms with my Nokia cell phone (C1-01) using AT Commands and I can successfully send SMS with this vb.net code.

Button_Send_Click:

Dim SMSPort = New SerialPort
    With SMSPort
        .PortName = "COM2"
        .BaudRate = 9600
        .Parity = Parity.None
        .DataBits = 8
        .StopBits = StopBits.One
        .Handshake = Handshake.None
        .DtrEnable = True
        .RtsEnable = True
        .NewLine = vbCrLf
    End With

    SMSPort.Open()

    SMSPort.Write("AT+CMGF=1" & vbCrLf)
    Threading.Thread.Sleep(200)

    SMSPort.Write("AT+CMGS=" & Chr(34) & TextBox1.Text & Chr(34) & vbCrLf) 'TextBox1.text = Recipient mobile number and chr(34) = "
    Threading.Thread.Sleep(200)

    SMSPort.Write("TEST MESSAGE" & Chr(26)) 'chr(26) = →
    Threading.Thread.Sleep(200)

    MsgBox(SMSPort.ReadExisting())

    SMSPort.Close()

It's working fine for the 1st time, after fire this code I received SMS on my cell phone TEST MESSAGE(Brilliant) BUT when I press send button in second time I received SMS on my cell phone which contains: AT+CMGF=1 AT+CMGS=+92XXYYYYYY TEST MESSAGE

Why in second time it's including "AT Commands i.e AT+CMGF etc.." in SMS? How can I remove unwanted text from this? I have also try SMSPort.DiscardInBuffer() and SMSPort.DiscardOutBuffer() Properties after opening and before closing my serial port (SMSPort) but my issue is not resolving. I have googled alot but all is vain, Please help me to resolve this issue.

Platform: Microsoft Visual Basic 2010 with .NET 2.0

Muhammad Saqib
  • 2,185
  • 3
  • 35
  • 48
  • Just curious why you are using AT commands on a Nokia phone. It will be a lot easier if you use a GSM library. I've used a couple of open source libraries and they work fine. I've also done AT commands on a microcontroller connected to a barebone GSM module and the thing is...you'll have to use a couple of delays so the GSM module can catch up with what you're sending to it :) – chris_techno25 Feb 23 '14 at 07:29

3 Answers3

1

First of all, you must seriously redo your AT command handling to

  • Read and parse the every single response line given back from the modem until you get a final result code. This applies for every single command line invocation, no exceptions whatsoever. See this answer for more details.
  • Never ever call Threading.Thread.Sleep in any code that handles AT commands. See this answer for more details about the risk of aborting the next command.
  • For AT+CMGS specifically you also MUST wait for the "\n\r> " response before sending data, see this answer (again) for more details.

Before fixing these fundamental issues you cannot expect any successful behaviour.

Community
  • 1
  • 1
hlovdal
  • 26,565
  • 10
  • 94
  • 165
  • Thank you for your answer, But it's too late and I have now working at another project. But Soon I will re-open this project and if your answer will helpful I will accept it. @hlovdal – Muhammad Saqib Dec 26 '13 at 08:26
0

OK, I came across the same issue today, and I solved it by adding "\r\n" to the end of the message, before sending CTRL+Z (char 26). You may try it with just "\n"

Ali Yousuf
  • 692
  • 8
  • 23
  • Thank you for your answer, But it's too late and I am currently working at another project. But Soon I will re-open this project and if your answer will helpful I will definitely accept it. @aly.yousuf7 – Muhammad Saqib Mar 23 '14 at 13:54
-1

Try this

Dim SMSPort = New SerialPort
    With SMSPort
        .PortName = "COM2"
        .BaudRate = 9600
        .Parity = Parity.None
        .DataBits = 8
        .StopBits = StopBits.One
        .Handshake = Handshake.None
        .DtrEnable = True
        .RtsEnable = True
        .NewLine = vbCrLf
End With

SMSPort.Open()

SMSPort.WriteLine("AT" & Chr(13))
Threading.Thread.Sleep(200)

SMSPort.WriteLine("AT+CMGF=1" & Chr(13))
Threading.Thread.Sleep(200)

SMSPort.WriteLine("AT+CMGS=" & Chr(34) & TextBox1.Text & Chr(34)) 
Threading.Thread.Sleep(200)

SMSPort.WriteLine("TEST MESSAGE" & Chr(26))
Threading.Thread.Sleep(200)

MsgBox(SMSPort.ReadExisting())

SMSPort.Close()

Add SMSPort.WriteLine("AT" & Chr(13)) and I replaced Write with WriteLine and removed vbCrlf. Also added Chr(13) to SMSPort.WriteLine("AT+CMGF=1")

Sharp Coders
  • 458
  • 5
  • 7