Click here to Skip to main content
15,896,539 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Guys,

I have done so many research the whole week and tried all different codes from google, yahoo. code projects. etc.

So far i have tried major links below:

http://code.msdn.microsoft.com/wpapps/Sending-SMS-Using-PC-COM-3d79e1d7[^]

http://www.daniweb.com/software-development/vbnet/threads/9537/sending-sms-using-vb.net[^]

Sending SMS using .NET[^]


My Actual Code is here:

For SMSCOMMS Class

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

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)
        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
        ReadThread = New Thread(AddressOf ReadPort)
    End Sub

    Public Function SendSMS(ByVal CellNumber As String,ByVal SMSMessage As String) As Boolean
        Dim MyMessage As String = Nothing
        'Check if Message Length <= 160
        If SMSMessage.Length <= 160 Then
            MyMessage = SMSMessage
        Else
            MyMessage = Mid(SMSMessage, 1, 160)
        End If
        If IsOpen = True Then
            SMSPort.WriteLine("AT+CMGS=" & CellNumber & vbCr)
            _ContSMS = False
            SMSPort.WriteLine(MyMessage & vbCrLf & Chr(26))
            _Continue = False
            RaiseEvent Sending(False)
        End If
    End Function

    Private Sub ReadPort()
        Dim SerialIn As String = Nothing
        Dim RXBuffer(SMSPort.ReadBufferSize) As Byte
        Dim SMSMessage As String = Nothing
        Dim Strpos As Integer = 0
        Dim TmpStr As String = Nothing

        While SMSPort.IsOpen = True
            If (SMSPort.BytesToRead <> 0) And (SMSPort.IsOpen = True) Then
                While SMSPort.BytesToRead <> 0
                    SMSPort.Read(RXBuffer, 0, SMSPort.ReadBufferSize)
                    SerialIn = SerialIn & System.Text.Encoding.ASCII.GetString(RXBuffer)
                    If SerialIn.Contains(">") = True Then
                        _ContSMS = True
                    End If
                    If SerialIn.Contains("+CMGS:") = True Then
                        _Continue = True
                        RaiseEvent Sending(True)
                        _Wait = False
                        SerialIn = String.Empty
                        ReDim RXBuffer(SMSPort.ReadBufferSize)
                    End If
                End While
                RaiseEvent DataReceived(SerialIn)
                SerialIn = String.Empty
                ReDim RXBuffer(SMSPort.ReadBufferSize)
            End If
        End While
    End Sub

    Public ReadOnly Property IsOpen() As Boolean
        Get
            If SMSPort.IsOpen = True Then
                IsOpen = True
            Else
                IsOpen = False
            End If
        End Get
    End Property

    Public Sub Open()
        If IsOpen = False Then
            SMSPort.Open()
            ReadThread.Start()
        End If
    End Sub

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



For Form1

Option Explicit On
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim SMSEngine As SMSCOMMS
        SMSEngine = New SMSCOMMS("COM5")
        SMSEngine.Open()
        SMSEngine.SendSMS("9234996080", "SMS Testing")
        SMSEngine.Close()
    End Sub
End Class


Still do not work at all. i am sure that Comp port number is 5 since i tried downloading SMS cast from smscaster.com and tried their trial API.

Also i have tried this

[^]

but this one is more complicated than i have imagine and it has a cost for license.
Posted
Updated 15-Jun-13 7:05am
v3

hello, you can try to use .BaudRate = 115200 for fastrack wavecom modem
 
Share this answer
 
I also found that problem. Changing BaudRate to 115200 solved the problem. Thanks.
 
Share this answer
 
Comments
Sascha Lefèvre 29-Apr-15 13:16pm    
You posted this as a solution but it is none. Please delete it. You can post it as a comment with the button "Have a Question or Comment?" instead. Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900