Question can't send sms

sebasjuh

Member
Joined
Dec 6, 2007
Messages
13
Programming Experience
Beginner
Hello,

I have a little problem. I have found a script on the internet that can send an sms through a GSM modem. Down here you can see the whole script I found:

Now the problem is, on the computer where I installed the GSM modem I can send a sms with Hyperterminal with the AT commands I used in the Vb.net script. But when I try to sms with the code here below it won't send any sms.

The modem is connected on the COM1 port and as I said with Hyperterminal I can just send text messages to mobile phones.

Can someone maybe help me and explain what I am doing wrong in vb.net?
Because I really want to send text messages with the vb.net script file and I can't seems to find the problem.


VB.NET:
Imports System
Imports System.Threading
Imports System.ComponentModel
Imports System.IO.Ports

Public Class Form1
    'connect your mobile/GSM modem to PC,
    'then go in device manager and check under ports which COM port has been slected
    'if say com1 is there then put com2 in following statement
    Dim SMSEngine As New SMSCOMMS("COM2")
    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
End Class
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
        Dim Quote = Chr(34)

        If SMSPort.IsOpen = True Then
            'sending AT commands
            SMSPort.WriteLine("AT" & Chr(13))
            SMSPort.WriteLine("AT+CPIN=" & Quote & "****" & Quote & Chr(13)) 'set command message format to text mode(1)
            SMSPort.WriteLine("AT+CMGF=1" & Chr(13)) 'set command message format to text mode(1)
            SMSPort.WriteLine("AT+CMGS=" & Quote & "+31*********" & Quote & Chr(13) & Chr(26)) ' enter the mobile number and text to send the SMS
            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
 
Back
Top