0

I'm trying to send many or bulk sms using AT Command. I try send all number inside the datagrid but only first number is sending.

this is my code

    Dim sql As New MySqlDataAdapter("select StudentID, StudentName,StudentContact, DueDate  FROM issue inner join student on student.StudentID = issue.Student  ", conn)
     Dim ds As New DataSet
    sql.Fill(ds, 0)
    For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
        Dim wholenum As String
        Dim wholesms As String
        wholenum = ds.Tables(0).Rows(i).Item(2).ToString
        wholesms = "Hello " & ds.Tables(0).Rows(i).Item(1).ToString & ",  this is your Due Date  " & ds.Tables(0).Rows(i).Item(3).ToString & " pls return it on your due date"

        If SerialPort1.IsOpen Then
            Try
                With SerialPort1
                    .Write("AT" & vbCrLf)
                    .Write("AT+CMGF=1" & vbCrLf)
                    .Write("AT+CMGS=" & Chr(34) & wholenum & Chr(34) & vbCrLf)
                    .Write(wholesms & Chr(26))



                    MsgBox("Success sa SEND")


                    'update one 

                    'Call ConnectDatabase()
                    'com = New MySqlCommand("UPDATE issue SET Sent='1' ", conn)
                    'com.ExecuteNonQuery()
                    'Call DisconnectDatabase()

                End With

            Catch ex As Exception
                MsgBox("Bad Signal or No load")
            End Try

        Else
            MsgBox("Pls insert a modem")
        End If

I think the looping is working 'cuz it apppears the successful message of how many inside in the datagrid view. But it only send the first number.

1 Answers1

0

You need to fix your AT command handling significantly. First of all you need to read and parse everything the modem sends back to you after sending a AT command line (which by the way should be terminated with just "\r" and not vbCrLf).

You should never start sending a new command line before you have received the Final result code. And for AT+CMGS specifically you should never send the sms payload before you have received the "\r\n >" prefix.

These issues are covered in this and this answer. But the very first thing you should to is to read all of the text in chapter 5 in the V.250 specification. It is a really important document when working with AT commands.

Community
  • 1
  • 1
hlovdal
  • 26,565
  • 10
  • 94
  • 165