How to extract sms message body from gsm modem using AT command set

clzanas

Member
Joined
Jul 15, 2009
Messages
16
Programming Experience
Beginner
Hi guys,

I am trying to extract received sms messages from my gsm modem and inserting them into sql database, but i am getting a lot of inconsistency errors due to the messages not coming in properly when i click on a button.

i used the substring method in vb.net to grab the message string but it is inconsistent due to the "ok" returned by the modem. Sometimes one time sometimes two. So the substring extracted often gets mixed up.

So now i am thinking of how to extract the sms message body contents only and inserting them to sql database.

the result i got from past try out is per attached.

I am using the AT command set in this prog.

below is my code

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click


'testing of AT command
'Dim rec As String = "REC UNREAD"
serialPort.WriteLine("AT+CMGR=1" & vbCrLf) 'send command over

receivedData = serialPort.ReadExisting() 'read command response


TextBox1.AppendText(receivedData)
'MsgBox(receivedData)
TextBox1.ScrollToCaret()

'connect to database

Dim sql As String


Dim connectionString As String = "Data Source=TEMASEK-8EA594C\SQLEXPRESS;Initial Catalog=sms compare;" & "Integrated Security=SSPI;"
conn = New SqlConnection(connectionString)
sql = "SELECT * FROM record"




da = New SqlDataAdapter(sql, conn)
conn.Open()
ds = New DataSet()
Dim commandBuilder As SqlCommandBuilder = New SqlCommandBuilder(da)
da.Fill(ds, "record")
bsource.DataSource = ds.Tables("record")
' DataGridView2.DataSource = bsource
conn.Close()


Dim tgt As String = Trim(receivedData)
Dim pnum As String
'MsgBox(pnum)
Dim msg As String
'MsgBox(msg)
Dim dsNewRow As DataRow

dsNewRow = ds.Tables("record").NewRow()

' dsNewRow.Item("PhoneNumber") = pnum
dsNewRow.Item("sms") = pnum

ds.Tables("record").Rows.Add(dsNewRow)

da.Update(ds, "record")


MsgBox("Phone Number and Message added to the Database")



End Sub

hope someone is able to help me. Thnks in advance.

regards,

Charles
 

Attachments

  • 2009-07-25_235552.png
    2009-07-25_235552.png
    1.1 KB · Views: 34
Back
Top