0

I am having some problems with my on going project. I am using vb2008 to send SMS using AT+Commands. So here is the code

Dim sender_port As New System.IO.Ports.SerialPort()
Private Sub btn_sender_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_sender.Click

'set port values
sender_port.PortName = "COM16"
sender_port.BaudRate = 115200
sender_port.Parity = IO.Ports.Parity.None
sender_port.StopBits = IO.Ports.StopBits.One
sender_port.DataBits = 8
sender_port.Handshake = IO.Ports.Handshake.RequestToSend
sender_port.DtrEnable = True
sender_port.RtsEnable = True
sender_port.NewLine = vbCrLf

sender_port.Open()

If sender_port.IsOpen Then
    Dim forSending As New MySqlDataAdapter("select * from sms_for_sending where dateSent = 0000-00-00 LIMIT 1", myconn)
    Dim myDataTable As New DataTable

    forSending.Fill(myDataTable)

    If myDataTable.Rows.Count = 1 Then
        'send message
        sender_port.Write("AT" & vbCrLf)
        sender_port.Write("AT+CMGF=1" & vbCrLf)
        sender_port.Write("AT+CMGS=" & Chr(34) & myDataTable.Rows(0).Item("recepient") & Chr(34) & vbCrLf)
        sender_port.Write(myDataTable.Rows(0).Item("message") & vbCrLf & vbCrLf & "Sent using SMS Server" & vbCrLf & "(do not reply)" & Chr(26))
    Else
        MessageBox.Show("Sender Port no Available", "SMS Server")
    End If
End If
End Sub

The message is sent successfully. But the message I receive is:

"
This is a test message

Sent using SMS Server
(do not reply)
"

istead of:

"This is a test message

Sent using SMS Server
(do not reply)
"

Please help. Thanks

EDIT: I did solved it.

I thought vbCrLf was just one function. But doing some research I found out that vbCrLf is equivalent to "\r\n" and vbCr alone is "\r" and vbLf is "\n".

I just changed vbCrLf to vbCr in

sender_port.Write("AT+CMGS=" & Chr(34) & myDataTable.Rows(0).Item("recepient") & Chr(34) & vbCrLf)

it is now

sender_port.Write("AT+CMGS=" & Chr(34) & myDataTable.Rows(0).Item("recepient") & Chr(34) & vbCr)
  • Instead of embedding the solution within the question, you can rather create an answer to your own question (that's ok and the proper way to do it). – hlovdal Jul 25 '14 at 09:48
  • Also you need to fix (lacking) AT command response handling in general, and specifically `\r\n> ` prefix handling for AT+CMGS, see [this answer](http://stackoverflow.com/a/16404193/23118). If your code currently works as expected you are just lucky. – hlovdal Jul 25 '14 at 09:55

0 Answers0