Results 1 to 6 of 6

Thread: using GSM modem to send SMS

  1. #1

    Thread Starter
    Registered User
    Join Date
    Apr 2014
    Posts
    2

    using GSM modem to send SMS

    Dear experts,

    I am doing my project and I am still new with visual basic. for my project, I need to send SMS using GSM modem using vb.net. I tried to send it using this program, but there is no reaction. I wonder what is wrong with the program. can you please take a look at this program and if anything wrong can you please tell me what it is. thank you for your help.

    Imports System
    Imports System.Threading
    Imports System.ComponentModel
    Imports System.IO.Ports

    Public Class Form1
    'connect mobile/GSM modem to PC,
    'then go in device manager and check under ports which COM port has been selected
    'if say com1 is there then put com2 in following statement
    Dim SMSEngine As New SMSCOMMS("COM23")
    Dim i As Integer
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    SMSEngine.Open() 'open the port
    SMSEngine.SendSMS() 'send the SMS

    End Sub

    Public Class SMSCOMMS
    Private WithEvents SMSPort As SerialPort
    Private SMSThread As Thread
    Private ReadThread As Thread
    Shared _Continue As Boolean = False
    Shared _ContSMS As Boolean = False
    Private _Wait As Boolean = False
    Shared _ReadPort As Boolean = False
    Public Event Sending(ByVal Done As Boolean)
    Public Event DataReceived(ByVal Message As String)

    Public Sub New(ByRef COMMPORT As String)
    'initialize all values
    SMSPort = New SerialPort
    With SMSPort
    .PortName = COMMPORT
    .BaudRate = 9600
    .Parity = Parity.None
    .DataBits = 8
    .StopBits = StopBits.One
    .Handshake = Handshake.RequestToSend
    .DtrEnable = True
    .RtsEnable = True
    .NewLine = vbCrLf
    End With
    End Sub
    Public Function SendSMS() As Boolean
    If SMSPort.IsOpen = True Then
    'sending AT commands
    SMSPort.WriteLine("AT")
    SMSPort.WriteLine("AT+CMGF=1" & vbCrLf) 'set command message format to text mode(1)
    SMSPort.WriteLine("AT+CSCA=""+60193900000""" & vbCrLf)
    SMSPort.WriteLine("AT+CMGS= + TextBox1.text + " & vbCrLf) ' enter the mobile number to send the SMS
    _ContSMS = False
    SMSPort.WriteLine("+ TextBox1.text +" & vbCrLf & Chr(26)) 'SMS sending
    MessageBox.Show(":send")
    SMSPort.Close()
    End If
    End Function

    Public Sub Open()
    If Not (SMSPort.IsOpen = True) Then
    SMSPort.Open()
    End If
    End Sub

    Public Sub Close()
    If SMSPort.IsOpen = True Then
    SMSPort.Close()
    End If
    End Sub
    End Class

  2. #2
    Fanatic Member
    Join Date
    Oct 2011
    Location
    Sydney, Australia
    Posts
    756

    Re: using GSM modem to send SMS

    Hi and welcome to the forums.
    Firstly when pasting code please wrap it in code tags, there is a button for them in the advanced editor, this makes things easier to read as it comes out like:
    Code:
    this is where code goes
    Now with the code. The first thing is making sure the modem can actually accept AT commands. Some modems need to be put into particular modes etc etc, Do you get any errors? what part doesn't work? Is the modem connected and assigned a COM port number?

    Start there and let us know
    My CodeBank Submissions
    • Listbox with transparency and picture support - Click Here
    • Check for a true internet connection - Click Here
    • Open Cash drawer connected to receipt printer - Click Here
    • Custom color and size border around form - Click Here
    • Upload file to website without user logins, includes PHP - Click Here
    • List All Removable USB Storage Devices - Click Here
    • Custom On/Off Slide Control - Click Here
    • Insert multiple rows of data into one database table using parameters - Click Here
    • Trigger USB/Serial Cash Drawer - Click Here

  3. #3
    Addicted Member
    Join Date
    Oct 2008
    Location
    USA
    Posts
    150

    Re: using GSM modem to send SMS

    looking at your code

    Code:
    'sending AT commands
    SMSPort.WriteLine("AT")
    SMSPort.WriteLine("AT+CMGF=1" & vbCrLf) 'set command message format to text mode(1)
    SMSPort.WriteLine("AT+CSCA=""+60193900000""" & vbCrLf) 
    SMSPort.WriteLine("AT+CMGS= + TextBox1.text + " & vbCrLf) ' enter the mobile number to send the SMS
    _ContSMS = False
    SMSPort.WriteLine("+ TextBox1.text +" & vbCrLf & Chr(26)) 'SMS sending
    this line

    Code:
    SMSPort.WriteLine("AT")
    is missing carriage return. I dont even think you need this line.

    Here

    Code:
    SMSPort.WriteLine("AT+CMGS= + TextBox1.text + " & vbCrLf) ' enter the mobile number to send the SMS
    SMSPort.WriteLine("+ TextBox1.text +" & vbCrLf & Chr(26)) 'SMS sending
    You are not correctly building the AT command.

    this might work.

    Code:
    SMSPort.WriteLine("AT+CMGS=" & TextBox1.text & vbCrLf) ' enter the mobile number to send the SMS
    _ContSMS = False
    SMSPort.WriteLine(TextBox1.text & vbCrLf & Chr(26)) 'SMS sending
    Why are you not checking the responses from the serialport? It would give you a better understanding why things are not working.

    Have you tried just sending the AT commands to the GSM modem with term to determine what the correct format is and the response you might expect back from the modem?
    Think.... Question.....

  4. #4

    Thread Starter
    Registered User
    Join Date
    Apr 2014
    Posts
    2

    Re: using GSM modem to send SMS

    thank you for the response...
    i'm sorry for the pasting code like that since i'm still new here but i will take a note on that.
    i have already make sure the modem can accept the AT commands because i have already tested with hyper terminal and it works.
    i have already test the GSM by sending and receiving the sms. the GSM that i used are Siemens TC35. before i running the program i have make sure that the modem is connected and assigned a COM port number which is com24. the problem is, when i tried to send the sms using this program, it does not show any error but the program says is running but does not give any response at all; not message box appeared saying the the sms is sending.

  5. #5
    Fanatic Member
    Join Date
    Oct 2011
    Location
    Sydney, Australia
    Posts
    756

    Re: using GSM modem to send SMS

    No worries about the tags.

    In regards to errors, you aren't catching them so place it in a try/catch end try. You should put in something that reads back any response the modem gives as 2ndmessiah has mentioned
    Code:
    Public Function SendSMS() As Boolean
    If SMSPort.IsOpen = True Then
    Try
    'sending AT commands
    SMSPort.WriteLine("AT")
    SMSPort.WriteLine("AT+CMGF=1" & vbCrLf) 'set command message format to text mode(1)
    SMSPort.WriteLine("AT+CSCA=""+60193900000""" & vbCrLf) 
    SMSPort.WriteLine("AT+CMGS= + TextBox1.text + " & vbCrLf) ' enter the mobile number to send the SMS
    _ContSMS = False
    SMSPort.WriteLine("+ TextBox1.text +" & vbCrLf & Chr(26)) 'SMS sending
    If SMSPort.BytesToRead > 0 Then
        Console.WriteLine(SMSPort.ReadExisting)
    End If 'i have not tested this nor do i know if its even going to work
    MessageBox.Show(":send")
    SMSPort.Close()
    Catch ex as Exception
    msgbox(ex.message)
    End Try
    End If
    End Function
    My CodeBank Submissions
    • Listbox with transparency and picture support - Click Here
    • Check for a true internet connection - Click Here
    • Open Cash drawer connected to receipt printer - Click Here
    • Custom color and size border around form - Click Here
    • Upload file to website without user logins, includes PHP - Click Here
    • List All Removable USB Storage Devices - Click Here
    • Custom On/Off Slide Control - Click Here
    • Insert multiple rows of data into one database table using parameters - Click Here
    • Trigger USB/Serial Cash Drawer - Click Here

  6. #6
    Addicted Member
    Join Date
    Oct 2008
    Location
    USA
    Posts
    150

    Re: using GSM modem to send SMS

    Your code is opening COM23. In your last post you said it is COM24.
    A minor oversight that might be causing you a problem.
    Think.... Question.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width